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

From: Prof Brian Ripley <>
Date: Mon, 04 Apr 2011 22:41:12 +0100 (BST)

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

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Mon 04 Apr 2011 - 21:43:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Apr 2011 - 17:00:41 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive