[R] Creating datasets

Douglas Bates bates at stat.wisc.edu
Fri Jun 3 15:06:24 CEST 2005


Jim Lemon wrote:
> Hi folks,
> 
> Having lost count of the times I have read the relevant section in
> R-exts.html (and by the way, where has that useful file gone? I had to
> look at it on CRAN.), searched for "creating datasets" (this is the
> first time that Jon Baron's excellent search site has let me down) and
> read the idiot's guide for creating packages, I am willing to admit that
> I have failed the test.
> 
> First:
> Linux (Fedora Core 2)
> R-2.1.0
> 
> I am attempting to integrate three functions that have been kindly
> donated to the plotrix package by Sander Oom dealing with plotting soil
> texture. Everything works okay, but I want to add a dataset to the
> package. R-exts says that three types of data files are okay:
> 
> R code, rectangular tables (e.g. CSV) or files created by save (.rda)
> 
> I note that all the "real" packages (oops, bundles) like MASS have three
> files in their data directory that look like an index of the datasets,
> the datasets themselves and something I haven't worked out yet. I
> haven't found a description of how to do that trick.

These are created from the original data sets when the package is
installed, provided that the LazyData switch is turned on in the
DESCRIPTION file or the call to R CMD INSTALL.

> Thus I created the dataset by reading a CSV data file into a data frame
> 
> oksoil<-read.table("oksoil.csv",sep=",")
> 
> That data frame works fine in all the functions. Then I saved it:
> 
> save(oksoil,file="/home/jim/R/plotrix/data/oksoil.rda")
> 
> But when I check the package, the examples don't work:
> 
> R CMD check /home/jim/R/plotrix
> ...
>>  data(oksoil)
> Warning in data(oksoil) : data set 'oksoil' not found
>>  # first just show the soil triangle
>>  soil.texture()
>>  # now plot the observations
>>  show.soil.texture(oksoil)
> Error in show.soil.texture(oksoil) : Object "oksoil" not found
> Execution halted

You must put the data set into a source package directory then install
the package using Rcmd INSTALL or R CMD INSTALL.  Some indices are
created during the installation process and it is these that allow R to
find the data sets by name.

> I promise to try writing an "Idiot's Guide to Creating Datasets" if
> someone can provide a method.




More information about the R-help mailing list