Arguments R / Sweave

I use R and Sweave to create a report.

R CMD Sweave MyReport.Rnw

I want to be able to send arguments to R-code, because the report is, of course, “Dynamic” . So I would like to do something like this:

R CMD SWeave MyReport.Rnw PatientId = 5

... and the R code reads the value PatientIdin the variable ...

How should I do it? Someone mentioned the use of environment variables, but this seems like not an elegant solution.

+5
source share
2 answers

, R, commandArgs(), , , R CMD Sweave . Sweave R -e,

R -e "Sweave('MyReport.Rnw')" --args PatientId=1

MyReport.Rnw commandArgs(TRUE), PatientId=1.

, Sweave() R script ; script

PatientId <- 1
Sweave("MyReport.Rnw")

MyReport.Rnw PatientId. , PatientId.

+5

"" , "":

  • , , sys.getenv()

  • ,

.. , R , :

rScriptOne.r                   # write to foo.txt
R CMD Sweave MyReport.Rnw      # reads from foo.txt
+1

All Articles