Paul.Rustomji at csiro.au
2008-Jul-28 06:08 UTC
[R] How to set directory Rscript runs in/Sweave output directory
Hello
I am using Sweave to generate some pdf reports using R on a Windows
platform and would like to control the output directory that the
generated .tex file goes to. Basically I use the following commands in
a batch file:
set outdir=c:/output/1234
Rscript -e Sweave('C:/pathpathpath/script.Rnw')
Which produces script.tex
Sweave has the option of specifying an output directory for figures, but
the .tex file is always created in the directory that the Rscript
command was initiated in via the batch file. So my questions are thus:
1. Can Rscript be invoked in a nominated directory (ie %outdir%) from
within a batchfile
2. Or Can Sweave direct the .tex output file to a nominated directory?
I have tried Rscript -e setwd(shell('echo %outdir%',intern=T)) -e
Sweave(....
to change the current working directory to %outdir% before invoking
Sweave but this doesn't seem to work in batch mode.
paul
Paul Rustomji
Rivers and Estuaries
CSIRO Land and Water
GPO Box 1666
Canberra ACT 2601
ph +61 2 6246 5810
mobile 0406 375 739
Prof Brian Ripley
2008-Jul-28 06:46 UTC
[R] How to set directory Rscript runs in/Sweave output directory
On Mon, 28 Jul 2008, Paul.Rustomji at csiro.au wrote:> Hello > > I am using Sweave to generate some pdf reports using R on a Windows > platform and would like to control the output directory that the > generated .tex file goes to. Basically I use the following commands in > a batch file: > > set outdir=c:/output/1234 > > Rscript -e Sweave('C:/pathpathpath/script.Rnw') > > Which produces script.tex > > Sweave has the option of specifying an output directory for figures, but > the .tex file is always created in the directory that the Rscript > command was initiated in via the batch file. So my questions are thus: > > 1. Can Rscript be invoked in a nominated directory (ie %outdir%) from > within a batchfileYes. Perhaps clearer, use cd mypath Rcmd Sweave script.Rnw> 2. Or Can Sweave direct the .tex output file to a nominated directory? > > I have tried Rscript -e setwd(shell('echo %outdir%',intern=T)) -e > Sweave(....The way to access environment variables in R is Sys.getenv().> to change the current working directory to %outdir% before invoking > Sweave but this doesn't seem to work in batch mode. > > paul > > Paul Rustomji > Rivers and Estuaries > CSIRO Land and Water > GPO Box 1666 > Canberra ACT 2601 > > ph +61 2 6246 5810 > mobile 0406 375 739 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Seemingly Similar Threads
- Rscript -e, Sweave and tempdir()
- problem running Sweave as a web service with anti-virus software
- Is there a way to avoid loading dependendent packages?
- Is conditional evaluation of R code chunks possible in Sweave ?
- problem with gls finding model terms without specifying data=named.object