From murdoch at stats.uwo.ca  Fri Sep  4 16:42:48 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 04 Sep 2009 10:42:48 -0400
Subject: [Rd] Rscript and default packages
In-Reply-To: <E240CFC0-B5A2-423A-9911-B67240BF8A74@r-project.org>
References: <4A9FCA3E.7090501@dbmail.com> <4A9FDF87.4000801@stats.uwo.ca>
	<4AA00253.6060101@dbmail.com>
	<E240CFC0-B5A2-423A-9911-B67240BF8A74@r-project.org>
Message-ID: <4AA12768.9000008@stats.uwo.ca>

On 9/4/2009 10:20 AM, Simon Urbanek wrote:
> On Sep 3, 2009, at 13:52 , 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.
>>
> 
> Well, what's wrong with:
> 
> #!/usr/bin/Rscript --default-packages=base
> 
> ginaz:sandbox$ time ./scr
> 
> real	0m0.045s
> user	0m0.027s
> sys	0m0.017s
> 
> .. as opposed to
> 
> #!/usr/bin/Rscript --default-packages=base
> 
> ginaz:sandbox$ time ./scr
> 
> real	0m0.201s
> user	0m0.166s
> sys	0m0.034s

Windows doesn't support the #! invocation, but that should work on all 
the other systems that would use scripts.

Duncan Murdoch



[Rd] Rscript and default packages
Duncan Murdoch