[Rd] S4 objects in the data directory

Robin Hankin rksh1 at cam.ac.uk
Thu Nov 12 10:50:15 CET 2009


Hi

[R-2.10.0; suse linux]

I am having difficulty creating S4 objects in the data directory of a 
package. I want
to create a bunch of simple S4 objects for use in the examples section 
of the Rd files.

It says in R-exts that:

" R code should be “self-sufficient” and not make use of extra 
functionality provided by the package, so that the data file can also be 
used without having to load the package"

My current minimal self-contained example follows.

le112:~% cat ./anRpackage/R/f.R
setClass("foo", representation=representation(x="numeric"))

le112:~% cat ./anRpackage/data/toy_foo.R
"toy_foo" <- new("foo",x=rep(2,7))

fails R CMD check (transcript below)

It fails because the class isn't defined. I can
add 'require(anRpackage)' to the toy_foo.R
but I'm not sure if this is consistent with the above
advice in R-exts (and it
fails R CMD check anyway).

What is best practice for creating a package with
"toy" S4 objects for use in the examples section
of the Rd files?


cheers


Robin








le112:~% R CMD check ./anRpackage
* checking for working pdflatex ... OK

[snip]

* checking data for non-ASCII characters ... NOTE
Error: "foo" is not a defined class
Call sequence:
8: stop(gettextf("\"%s\" is not a defined class", Class), domain = NA)
7: getClass(Class, where = topenv(parent.frame()))
6: new("foo", x = rep(2, 7))
5: eval(expr, envir, enclos)
4: eval(i, envir)
3: sys.source(zfile, chdir = TRUE, envir = envir)
2: switch(ext, R = , r = {
library("utils")
sys.source(zfile, chdir = TRUE, envir = envir)
}, RData = , rdata = , rda = load(zfile, envir = envir), TXT = ,
txt = , tab = , tab.gz = , tab.bz2 = , tab.xz = , txt.gz = ,
txt.bz2 = , txt.xz = assign(name, read.table(zfile, header = TRUE,
as.is = FALSE), envir = envir), CSV = , csv = , csv.gz = ,
csv.bz2 = , csv.xz = assign(name, read.table(zfile, header = TRUE,
sep = ";", as.is = FALSE), envir = envir), found <- FALSE)
1: utils::data(list = f, package = character(0L), envir = dataEnv)
Execution halted
Portable packages use only ASCII characters in their datasets.
* checking examples ...no parsed files found
NONE

WARNING: There were 2 warnings, see
/home/rksh/anRpackage.Rcheck/00check.log
for details

le112:~%



-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877



More information about the R-devel mailing list