[BioC] rcmd check does not recognize generic function definitions

Robert Gentleman rgentlem@jimmy.harvard.edu
Tue, 18 Feb 2003 00:16:02 -0500


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   |
+---------------------------------------------------------------------------+