[Rd] Rscript and default packages

Duncan Murdoch murdoch at stats.uwo.ca
Fri Sep 4 03:32:18 CEST 2009


On 03/09/2009 1:52 PM, Romain Francois wrote:
> On 09/03/2009 05:23 PM, Duncan Murdoch wrote:
>> On 03/09/2009 9:53 AM, Romain Francois wrote:
>>> Hi,
>>>
>>> Is is possible to embed inside an R script, the name of the default
>>> packages to be loaded when the script is invoked with Rscript.
>>>
>>> I know about the --default-packages argument, but I was wondering if
>>> there was a mechanism to embed this information within the script itself
>> I don't understand what you'd want here that you don't get with attach()
>> or require(). Why does it matter if they are default?
>>
>> Duncan Murdoch
> 
> Sorry for being vague. I am more interested in not loading some packages:
> 
> $ time Rscript  -e "#"
> 
> real	0m0.224s
> user	0m0.188s
> sys	0m0.032s
> 
> 
> $ time Rscript --default-packages="base" -e "#"
> 
> real	0m0.067s
> user	0m0.033s
> sys	0m0.016s
> 
> 
> $ time r -e "#"
> 
> real	0m0.039s
> user	0m0.032s
> sys	0m0.006s
> 
> This is related to the "How to ship R scripts with R packages" thread. 
> I'd like for example to ship a script that I know only requires the 
> "base" package. How would I specify this from within the script.

Okay, I get it.  I don't think there's any way to do that.  Rscript 
doesn't look at the script, it just sends it to Rterm after possibly 
setting R_DEFAULT_PACKAGES.  So your script has no way to say it just 
needs base, you need to know that before you run it.

Duncan Murdoch



More information about the R-devel mailing list