[Rd] data() in data/*.R files

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Nov 29 12:34:30 CET 2004

Robin Hankin wrote:

> Hi
> I'm having difficulty making a package pass R CMD check.
> I need to read in a dataset from another package,  modify it, and have the
> modified object available in the first package. help(require) says:
>       The source code for a package that requires one or more other
>       packages should have a call to 'require', preferably near the
>       beginning of the source, and of course before any code that uses
>       functions, classes or methods from the other package.
> and 200update.txt points out that the  data/*.R files must be self
> sufficient, suggesting  "require(pkg, quietly=TRUE, save=FALSE)"
> if needed.  My .R file  in the data subdirectory looks like this:
>    require(calibrator, quietly=TRUE, save=FALSE)
>    data(expert.estimates, package="calibrator")
>    <paraphrase>
>   expert.estimates.modified <- some.function(expert.estimates)
>    </paraphrase>
>   But if I do this, R CMD check says
> Error in eval(expr, envir, enclos) : couldn't find function "data"
> Execution halted
> ERROR: installing package indices failed
> Installation failed.
> [the package passes R CMD check if I cut-and-paste a dput  and assign 
> expert.estimates.modified
> directly, and dispense with the data() statement].
> How do I load a dataset from another package in a .R file, and use it?

You need to require(utils) (the package data() is in),
as well as a corresponsing entry in the DESCRIPTION file.
Also, for Windows, you may need to add the line
ZipData: no
to your DESCRIPTION file, but I am not sure about the latter (and 
haven't tested yet).



More information about the R-devel mailing list