rcmd check does not recognize generic function definitions
1
0
Entering edit mode
@gordon-smyth
Last seen 6 hours ago
WEHI, Melbourne, Australia
Dear all, I am trying to package up some microarray data analysis code into a bioconductor package and, naturally, I want to define some new generic functions using the methods library. I have not been able to get my package to pass rcmd check. In particular, generic functions which I have defined are not recognized when rcmd check tries out the examples. However, all the examples work correctly if I actually build the library using rcmd build, then install it and load it in my R session using library. The examples then work correctly if I paste them into my R session. I have isolated the problem (no doubt only one of many) in a trivial example which I give below. I get similar results with R 1.6.2 under Windows 2000 and with R 1.6.1 under linux. I am happily running rcmd check on libraries which do not use the formal methods of the package methods. Questions: 1. Is rcmd check intended to work properly with formal S4-style classes and methods? 2. How can I change my code so that it passes rcmd check? 3. Does the failure with rcmd check indicate a genuine problem with my code? 4. Is there any documentation that I should be reading? (The R document "Writing R Extensions" says that it does not cover formal methods of package methods of R. The "green book" by Chambers does not cover anything R specific. I have not found any HowTo's, Vignettes or FAQs on bioconductor.org which deal with writing code for Bioconductor.) Any help or feedback gratefully recieved. Gordon My trivial example is a test library called "test". The directory test/R contains one file "test.R" and the directory test/man contains one file "myGenericFun.Rd". The file contents are: --------------------------------- test.R ---------------------------------- require(methods) setGeneric("myGenericFun", function(object) standardGeneric("myGenericFun")) setMethod("myGenericFun","ANY", function(object) paste("myGenericFun on object of class",class(object)) ) setMethod("myGenericFun","matrix", function(object) "myGenericFun for matrices" ) --------------------------------- end test.R ------------------------------ ---------------------- start myGenericFun.Rd ------------- \name{myGenericFun} \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) # x is a vector dim(x) <- c(5,2) myGenericFun(x) # x is now a matrix } \keyword{models} ------------------------- end myGenericFun.Rd --------------------------- If I source the file test.R to my R session and then run for myself the code in the example, it works fine: > x <- rnorm(10) > myGenericFun(x) [1] "myGenericFun on object of class numeric" > dim(x) <- c(5,2) > myGenericFun(x) [1] "myGenericFun for matrices" However rcmd check fails because it does not detect any code objects defined. I have tried it with R 1.6.1 under linux and with R 1.6.2 under Windows 2000. The log-file from rcmd check using R 1.6.2 under Windows 2000 is: * using log directory 'C:/Gordon/lib/R/test.Rcheck' * checking for file 'test/DESCRIPTION' ... OK * checking if this is a source package ... OK * checking package directory ... OK * checking DESCRIPTION Package field ... OK * checking DESCRIPTION Version field ... OK * checking DESCRIPTION License field ... OK * checking DESCRIPTION Description field ... OK * checking DESCRIPTION Title field ... OK * checking DESCRIPTION Author field ... OK * checking DESCRIPTION Maintainer field ... OK * checking DESCRIPTION Depends field ... OK * checking index files ... OK * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking generic/method consistency ... OK * checking for assignment functions with final arg not named 'value' ... OK * checking Rd files ... OK * checking for undocumented objects ... WARNING Warning message: Neither code nor data objects found in: undoc(dir = "C:/Gordon/lib/R/test") * checking for code/documentation mismatches ... WARNING Objects with usage in documentation object 'myGenericFun' but missing from code: [1] "myGenericFun" * checking for undocumented arguments in \usage ... OK * creating test-Ex.R ... OK * checking examples ... ERROR Running examples failed. The examples output file ends with the error, "Error: couldn't find function "myGenericFun"". Under linux the output from RCMD check is somewhat less explanatory, but I think still relates to the same problem: * checking for working latex ... OK * using log directory '/export/share/disk501/lab0605/wettenhall/Rlibs/test.Rcheck' * checking for file 'test/DESCRIPTION' ... OK * checking if this is a source package ... OK * Installing *source* package 'test' ... ** R ** help >>> Building/Updating help pages for package 'test' Formats: text html latex example myGenericFun text html latex example * DONE (test) * DONE (INSTALL) * checking package directory ... OK * checking for sufficient/correct file permissions ... OK * checking DESCRIPTION Package field ... OK * checking DESCRIPTION Version field ... OK * checking DESCRIPTION License field ... OK * checking DESCRIPTION Description field ... OK * checking DESCRIPTION Title field ... OK * checking DESCRIPTION Author field ... OK * checking DESCRIPTION Maintainer field ... OK * checking DESCRIPTION Depends field ... OK * checking index files ... OK * checking R files for syntax errors ... OK * checking R files for library.dynam ... OK * checking generic/method consistency ... OK * checking for assignment functions with final arg not named 'value' ... OK * checking Rd files ... OK * checking for undocumented objects ... ERROR Error in undoc(package = "test") : invalid subscript type ---------------------------------------------------------------------- ----------------- 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@wehi.edu.au, www: http://www.statsci.org
Microarray Microarray • 2.2k views
ADD COMMENT
0
Entering edit mode
rgentleman ★ 5.5k
@rgentleman-7725
Last seen 9.0 years ago
United States
On Tue, Feb 18, 2003 at 04:08:51PM +1100, Gordon Smyth wrote: > Dear all, > > I am trying to package up some microarray data analysis code into a > bioconductor package and, naturally, I want to define some new generic > functions using the methods library. I have not been able to get my package > to pass rcmd check. In particular, generic functions which I have defined > are not recognized when rcmd check tries out the examples. However, all > the examples work correctly if I actually build the library using rcmd > build, then install it and load it in my R session using library. The > examples then work correctly if I paste them into my R session. > > I have isolated the problem (no doubt only one of many) in a trivial > example which I give below. > > I get similar results with R 1.6.2 under Windows 2000 and with R 1.6.1 > under linux. I am happily running rcmd check on libraries which do not use > the formal methods of the package methods. > > Questions: > 1. Is rcmd check intended to work properly with formal S4-style classes and > methods? Yes > 2. How can I change my code so that it passes rcmd check? If you look at any of the Bioconductor packages you will see that we use a method of assigning the generic functions into the packages;; this is done by putting a call to a function in First.Lib which ensures that happens. There are other methods to achieve this, I just use that one because I can remember it. What is happening is that the generic is being defined in the workspace (global env) nto the package > 3. Does the failure with rcmd check indicate a genuine problem with my code? > 4. Is there any documentation that I should be reading? (The R document > "Writing R Extensions" says that it does not cover formal methods of > package methods of R. The "green book" by Chambers does not cover anything > R specific. I have not found any HowTo's, Vignettes or FAQs on > bioconductor.org which deal with writing code for Bioconductor.) > Sorry, we are working on providing better documentation. For now, I can only commend the examples that are the code.... Robert > Any help or feedback gratefully recieved. > Gordon > > > My trivial example is a test library called "test". The directory test/R > contains one file "test.R" and the directory test/man contains one file > "myGenericFun.Rd". The file contents are: > > --------------------------------- test.R ---------------------------------- > require(methods) > > setGeneric("myGenericFun", > function(object) standardGeneric("myGenericFun")) > > setMethod("myGenericFun","ANY", > function(object) paste("myGenericFun on object of class",class(object)) > ) > > setMethod("myGenericFun","matrix", > function(object) "myGenericFun for matrices" > ) > --------------------------------- end test.R ------------------------------ > > ---------------------- start myGenericFun.Rd ------------- > \name{myGenericFun} > \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) # x is a vector > dim(x) <- c(5,2) > myGenericFun(x) # x is now a matrix > } > > \keyword{models} > ------------------------- end myGenericFun.Rd --------------------------- > > If I source the file test.R to my R session and then run for myself the > code in the example, it works fine: > > > x <- rnorm(10) > > myGenericFun(x) > [1] "myGenericFun on object of class numeric" > > dim(x) <- c(5,2) > > myGenericFun(x) > [1] "myGenericFun for matrices" > > However rcmd check fails because it does not detect any code objects > defined. I have tried it with R 1.6.1 under linux and with R 1.6.2 under > Windows 2000. The log-file from rcmd check using R 1.6.2 under Windows 2000 is: > > * using log directory 'C:/Gordon/lib/R/test.Rcheck' > * checking for file 'test/DESCRIPTION' ... OK > * checking if this is a source package ... OK > * checking package directory ... OK > * checking DESCRIPTION Package field ... OK > * checking DESCRIPTION Version field ... OK > * checking DESCRIPTION License field ... OK > * checking DESCRIPTION Description field ... OK > * checking DESCRIPTION Title field ... OK > * checking DESCRIPTION Author field ... OK > * checking DESCRIPTION Maintainer field ... OK > * checking DESCRIPTION Depends field ... OK > * checking index files ... OK > * checking R files for syntax errors ... OK > * checking R files for library.dynam ... OK > * checking generic/method consistency ... OK > * checking for assignment functions with final arg not named 'value' ... OK > * checking Rd files ... OK > * checking for undocumented objects ... WARNING > Warning message: > Neither code nor data objects found in: undoc(dir = "C:/Gordon/lib/R/test") > * checking for code/documentation mismatches ... WARNING > Objects with usage in documentation object 'myGenericFun' but missing from > code: > [1] "myGenericFun" > > * checking for undocumented arguments in \usage ... OK > * creating test-Ex.R ... OK > * checking examples ... ERROR > Running examples failed. > > The examples output file ends with the error, "Error: couldn't find > function "myGenericFun"". > > Under linux the output from RCMD check is somewhat less explanatory, but I > think still relates to the same problem: > > * checking for working latex ... OK > * using log directory > '/export/share/disk501/lab0605/wettenhall/Rlibs/test.Rcheck' > * checking for file 'test/DESCRIPTION' ... OK > * checking if this is a source package ... OK > > * Installing *source* package 'test' ... > ** R > ** help > >>> Building/Updating help pages for package 'test' > Formats: text html latex example > myGenericFun text html latex > example > * DONE (test) > > * DONE (INSTALL) > > * checking package directory ... OK > * checking for sufficient/correct file permissions ... OK > * checking DESCRIPTION Package field ... OK > * checking DESCRIPTION Version field ... OK > * checking DESCRIPTION License field ... OK > * checking DESCRIPTION Description field ... OK > * checking DESCRIPTION Title field ... OK > * checking DESCRIPTION Author field ... OK > * checking DESCRIPTION Maintainer field ... OK > * checking DESCRIPTION Depends field ... OK > * checking index files ... OK > * checking R files for syntax errors ... OK > * checking R files for library.dynam ... OK > * checking generic/method consistency ... OK > * checking for assignment functions with final arg not named > 'value' ... OK > * checking Rd files ... OK > * checking for undocumented objects ... ERROR > Error in undoc(package = "test") : invalid subscript type > -------------------------------------------------------------------- ------------------- > 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@wehi.edu.au, www: http://www.statsci.org > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > http://www.stat.math.ethz.ch/mailman/listinfo/bioconductor -- +--------------------------------------------------------------------- ------+ | Robert Gentleman phone : (617) 632-5250 | | Associate Professor fax: (617) 632-2444 | | Department of Biostatistics office: M1B20 | | Harvard School of Public Health email: rgentlem@jimmy.dfci.harvard.edu | +--------------------------------------------------------------------- ------+
ADD COMMENT
0
Entering edit mode
On Tue, Feb 18, 2003 at 12:16:02AM -0500, Robert Gentleman wrote: > On Tue, Feb 18, 2003 at 04:08:51PM +1100, Gordon Smyth wrote: > > Dear all, > > > > I am trying to package up some microarray data analysis code into a > > bioconductor package and, naturally, I want to define some new generic > > functions using the methods library. I have not been able to get my package > > to pass rcmd check. In particular, generic functions which I have defined > > are not recognized when rcmd check tries out the examples. However, all > > the examples work correctly if I actually build the library using rcmd > > build, then install it and load it in my R session using library. The > > examples then work correctly if I paste them into my R session. Looks like a variant of "forget 'where=where'". As Robert said, pick one package in bioC (say Biobase). .First.lib is defined in a file called zzz.R (seems to be a tacit convention to call files that do that this way in packages). Forgeting the argument 'where' when defining a S4-style method is something I remember doing quite few times in the begining (and it made R check not so happy while the stuff was working when doing copy/paste). Hopin' it helps, L.
ADD REPLY
0
Entering edit mode
Dear all, Thanks to Robert and Laurent for help. My repaired code is given below. RCMD check now runs the examples fine. My question now is, how can I stop RCMD check from giving the warning that my generic function is documented but missing from the code? Is the format of my .Rd file correct? Here is the message: * checking for code/documentation mismatches ... WARNING Objects with usage in documentation object 'myGenericFun' but missing from code: [1] "myGenericFun" 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" ) } .First.lib <- function(libname, pkgname, where) { 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)) } ------------------------- 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}
ADD REPLY
0
Entering edit mode
Dear Laurent, Thanks for your tip to look at zzz.R in Biobase. Here's a piece of code that occurs in zzz.R for Biobase and for many of the other bioconductor packages: .First.lib <- function(libname, pkgname, where) { require(methods, quietly=TRUE) where <- match(paste("package:", pkgname, sep=""), search()) I think that I'm starting to understand this, but just to make sure ... the "where" in the first line "function(libname, pkgname, where)" really is superfluous, an unused argument. Right? The code would work just as well as .First.lib <- function(libname, pkgname) { require(methods, quietly=TRUE) where <- match(paste("package:", pkgname, sep=""), search()) Or is there something really, really, mysterious going on? Best Gordon At 04:41 PM 18/02/2003, Laurent Gautier wrote: >On Tue, Feb 18, 2003 at 12:16:02AM -0500, Robert Gentleman wrote: > > On Tue, Feb 18, 2003 at 04:08:51PM +1100, Gordon Smyth wrote: > > > Dear all, > > > > > > I am trying to package up some microarray data analysis code into a > > > bioconductor package and, naturally, I want to define some new generic > > > functions using the methods library. I have not been able to get my > package > > > to pass rcmd check. In particular, generic functions which I have > defined > > > are not recognized when rcmd check tries out the examples. However, all > > > the examples work correctly if I actually build the library using rcmd > > > build, then install it and load it in my R session using library. The > > > examples then work correctly if I paste them into my R session. > >Looks like a variant of "forget 'where=where'". As Robert said, pick >one package in bioC (say Biobase). .First.lib is >defined in a file called zzz.R (seems to be a tacit convention to call >files that do that this way in packages). Forgeting the argument 'where' >when defining a S4-style method is something I remember doing quite few >times in the begining (and it made R check not so happy while the stuff >was working when doing copy/paste). > >Hopin' it helps, > >L.
ADD REPLY

Login before adding your answer.

Traffic: 998 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6