[R] Rcmd check does not recognize formal generic function as code object
Gordon Smyth
smyth at wehi.edu.au
Wed Feb 19 05:45:03 CET 2003
Dear all,
I am trying to write a package using formal methods and classes from the
methods package. I have not been able to get the package to pass rcmd check
without warnings, because rcmd check does not recognize my generic
functions as code objects and therefore queries why they have documentation
entries.
I have isolated the problem in a very small trivial example which I give
below. I have one file test.R in the R directory and one file test.Rd in
the man directory. Here is the message from rcmd check:
* checking for code/documentation mismatches ... WARNING
Objects with usage in documentation object 'myGenericFun' but missing
from code:
[1] "myGenericFun"
Can I get rcmd check to recognize that myGenericFun is something that need
a documentation entry?
The document "Writing R Extensions" doesn't cover formal methods and
classes, and I haven't found any other documentation that covers writing
packages using formal methods. I am working from looking at code in
Bioconductor, pixmap and gpclib. I downloaded source for pixmap and
confirmed that it has the same problem with rcmd check that I mention here.
Any advice gratefully received, including any tips about how to write
organise .Rd files for generic methods.
Thanks
Gordon
-------------------------------- test.R -----------------------------
.initClassesandMethods <- function(where) {
setGeneric("myGenericFun",where=where,
def=function(object) standardGeneric("myGenericFun"))
setMethod("myGenericFun","ANY",where=where,
def=function(object) paste("myGenericFun on object of
class",class(object)))
setMethod("myGenericFun","matrix",where=where,
def=function(object) "myGenericFun for matrices")
}
# Use of .First.lib ensures that the new generic function is assigned in
the package itself
.First.lib <- function(libname, pkgname) {
require(methods, quietly=TRUE)
# Find what position in the search path this package is
where <- match(paste("package:", pkgname, sep=""), search())
.initClassesandMethods(where)
cacheMetaData(as.environment(where))
}
------------------------- end test.R ----------------------------------
------------------------- myGenericFun.Rd ------------------------
\name{myGenericFun}
\docType{methods}
\alias{myGenericFun}
\title{My Generic Function}
\description{A simple example generic function.}
\usage{myGenericFun(object)}
\arguments{
\item{object}{Any R object. A special method exists for objects of class
"matrix".}
}
\value{A character string explaining the class of object and the method
dispatched.}
\examples{
x <- rnorm(10)
myGenericFun(x)
dim(x) <- c(5,2)
myGenericFun(x)
}
\keyword{models}
-------------------------------- end myGenericFun.Rd -------------------
---------------------------------------------------------------------------------------
Dr Gordon K Smyth, Senior Research Scientist, Bioinformatics,
Walter and Eliza Hall Institute of Medical Research,
1G Royal Parade, Parkville, Vic 3050, Australia
Tel: (03) 9345 2326, Fax (03) 9347 0852,
Email: smyth at wehi.edu.au, www: http://www.statsci.org
More information about the R-help
mailing list