[Rd] Use keep.source for function in package with lazy loading

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Apr 10 12:51:55 CEST 2011


R-devel now has a KeepSource DESCRIPTION field to accomplish what I 
think you are seeking.

On Tue, 5 Apr 2011, Greg Snow wrote:

> Prof. Ripley,
>
> Thanks for the explanation.  I had set both keep.source and keep.source.packages to TRUE for my experiments, but had not realized that a new R process would be involved, so did not try the environmental variable approach.
>
>> From what you say below, I don't think I am going to accomplish what I wanted, since I want the source to show for users other than myself and there does not seem to be a reasonable way to change the users environment before installing my package (that is getting a bit too big brother to even think about).  I was hoping that there might be some switch somewhere that I had missed that would say keep the source for this function even though the default is not to.  But, it does not look like there is anything like that, and it is not worth implementing just for my one little use.
>
> Hmm, maybe I can set the source manually using .onAttach, I'll have to experiment some more.
>
> Thanks,
>
> -- 
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
>
>
>> -----Original Message-----
>> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
>> Sent: Monday, April 04, 2011 3:41 PM
>> To: Greg Snow
>> Cc: R-devel at r-project.org
>> Subject: Re: [Rd] Use keep.source for function in package with lazy
>> loading
>>
>> On Mon, 4 Apr 2011, Greg Snow wrote:
>>
>>> I have a function in one of my packages that I would like to print
>>> using the original source rather than the deparse of the function.
>>> The package uses lazy loading and the help page for library (under
>>> keep.source) says that keep.source does not apply to packages that
>>> use lazy loading and that whether those functions keep the source
>>> depends on when they are installed.
>>
>> Not quite: it is says it is 'determined when it is installed'.
>>
>> For a package that does not use lazy loading, what is installed is a
>> file of R code.  When library() loads such a package, it sources() the
>> R code, and at that point has the option to keep the source or not
>> (for that R session).
>>
>> For a package which uses lazy loading, the source()ing happens when
>> the package is installed: the objects created are then dumped into a
>> database.  Whether the source attribute is retained at that point
>> depends on the setting of the option "keep.source.pkgs". So if you can
>> arrange to install the package with that option set to true, in
>> principle (and in my experiments) the source attributes are retained.
>>
>> The easiest way to do this would seem to be to set the environment
>> variable R_KEEP_PKG_SOURCE to "yes" whilst installing the package.
>>
>>> This package is on R-forge and is being built there (and will
>>> eventually be used to submit the next version of the package to
>>> CRAN).
>>>
>>> I am not sure what the help means by 'installed', I have set the
>>> options to keep the source to TRUE before calling install.package,
>>> but that does not seem to work.
>>
>> I presume you mean keep.source.pkgs, not keep.source?  That needs to
>> be set in the process which is installing the package:
>> install.packages() calls R CMD INSTALL in a separate process.
>>
>>> Is there a way to "strongly encourage" the source to be kept for
>>> this function (or the entire package)?
>>>
>>> Thanks,
>>>
>>> --
>>> Gregory (Greg) L. Snow Ph.D.
>>> Statistical Data Center
>>> Intermountain Healthcare
>>> greg.snow at imail.org
>>> 801.408.8111
>>
>> --
>> 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
>

-- 
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-devel mailing list