[R] Rscript -e, Sweave and tempdir()

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Oct 16 07:59:37 CEST 2008


My first thought was that this is R < 2.7.2 and you have encountered
(from the CHANGES file)

    o   Rscript -e (and Rterm -e) failed on Vista because the MSVCRT
        function 'tmpfile' is broken on that platform.

But that couldn't possibly be the case, as the posting guide required you 
to update your R before posting (and tell us lots of information I don't 
see, including your OS).

On Thu, 16 Oct 2008, Paul.Rustomji at csiro.au wrote:

>
> 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
>
> ______________________________________________
> 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



More information about the R-help mailing list