I have an R script that accepts command line arguments that I want to convert to an Rtex or Rnw file to be knitted with a command like:
knit('myScript.Rtex "-args arg1=a arg2=b"')
but I cannot figure out how to get my command line arguments into myScript.Rtex [for evaluation therein by args <- commandArgs()]. I am trying to avoid writing temporary files that could contain the same information and be read by myScript.Rtex, because that seems unnecessarily untidy. Please can somebody provide a suggestion/solution?
So, long story short, how best to get information into a chunk in a .Rnw file that is equivalent (or at least similar) to processing command line arguments in a .R file?
Edit: Incorporating code from comments below
I want to use them in the computation. For example, I had an R script run like
R CMD BATCH --slave --no-save --no-restore "--args input=blah" myScript.R
Now I'd like to pass the same argument to myScript.Rnw, which is a version of myScript.R, but interspersed LaTeX and R code chunks. So the broader issue is simply that for knitr report processing to be useful for me I need a way to change the data that the report is run on. I have a workaround - but I'd sure like to know if I can pass command line arguments to a chunk in my .Rnw file. Right now I cannot do that.
This is my workaround:
#!/bin/bash
if [ $# -ne 2 ];
then ` echo "Usage: $0 refdir cmpdir" exit 1`
fi
export CSPP_VIIRS_EDR_REFERENCE_DIR=$1
export CSPP_VIIRS_EDR_COMPARISON_DIR=$2
script=$(dirname $0)'/viirs_edr_UseR_compare.Rnw'
R --slave --no-save --no-restore -e "require(knitr); knit('$script')" &> viirs_edr_UseR_compare.log
pdflatex viirs_edr_UseR_compare.tex
exit 0
I use Sys.getenv() in *viirs_edr_UseR_compare.Rnw* to extract parameters I want to pass, e.g., CSPP_VIIRS_EDR_REFERENCE_DIR.
knitcommandn it expected something like , ..knit(input, output,...)knitr: github.com/yihui/knitr/blob/master/inst/bin/knit but it is not clear to me what you want to do with the--args-- do you want to pass them toknit(), or use them in your computation?