[R] Rscript -e, Sweave and tempdir()
Paul.Rustomji at csiro.au
Paul.Rustomji at csiro.au
Thu Oct 16 06:56:19 CEST 2008
Hello R-Help
I have a question about the "behind the scenes" behaviour of the Rscript -e command and particularly its interaction with Sweave and tempdir().
We are trying to deploy R as a web service to do water quality analyses and have been writing software to call Sweave via Rscript eg:
cmd> Rscript -e Sweave('sweavefile.Rnw')
One problem we have been having is that Sweave tries to write temporary files in a temporary directory given by the tempdir() command (as per an email from F. Leitsch appended below). This is where our problem seems to lie.
As a simplified example, if we call
cmd> Rscript -e tempdir()
from our web service we get a win32(Cannot read memory:0x00000037) error message unless we grant Read+Write permissions to the root directory, which we are trying to avoid doing for security reasons. This suggests Sweave(?) is trying to write to somewhere else OTHER than tempdir() perhaps.
However if we run:
Rscirpt "testdir.r" (ie. "sourcing" a file without the -e option)
where testdir.r contains:
outpath <- tempdir()
write.table(outpath,"D:\\Internet\\RWebService\\Data\\dir.txt")
there appears to be no problem with the call to the tempdir() command. Also if we put the call to Sweave within a call2sweave.r file and do
cmd>Rscript call2sweave.r (ie. run sweave via a file that is sourced, rather than using the -e option)
then things go OK.
In short, something seems to be happening with the -e version of Rscript, the tempdir() command and its invocation by Sweave.
Any ideas?
Thanks
Paul.
EARLIER EMAIL FROM F. LEISCH (AUTHOR OF SWEAVE)
___________________________________
It's not figures but text output which is collected via temporary files. The corresponding code in Sweave is:
tmpcon <- file()
sink(file=tmpcon)
err <- NULL
if(options$eval) err <- evalFunc(ce, options)
cat("\n") # make sure final line is complete
sink()
output <- readLines(tmpcon)
close(tmpcon)
So you need to figure out where file() opens the anoymous temporary file on your operating system. His is the same place as a call to
tempdir() shows, e.g. on my Linux box:
R> tempdir()
[1] "/tmp/RtmpIzi6Yv"
so it tries to write under /tmp.
_____________________________________________
Paul Rustomji
Rivers and Estuaries
CSIRO Land and Water
GPO Box 1666
Canberra ACT 2601
ph +61 2 6246 5810
mobile 0406 375 739
More information about the R-help
mailing list