Dear R developers, I am having a slightly weird issue with a S4 method defined in my package adegenet 1.2-4, with R 2.11.0. As far as I know, the problem is new, and the code implementing the method has not changed for more than a year and worked well so far.
The problem is the following. I define, in the package, a method "[" for the S4 class 'genind'. The method's definition is: setMethod("[", signature(x="genind", i="ANY", j="ANY", drop="ANY"), function(x, i, j, ..., loc=NULL, treatOther=TRUE, drop=FALSE) { ... ## code of the function }) When sourcing the code directly from R, this method is found and used normally. However, when loading the package, the method does not seem to be "found" any longer by the dispatcher. For instance, here is an error I get: ### R code > library(adegenet) > data(nancycats) # nancycat is a S4 object with class 'genind' > class(nancycats) [1] "genind" attr(,"package") [1] "adegenet" > nancycats[1] Error in nancycats[1] : object of type 'S4' is not subsettable # "[" IS NOT USED HERE ### end R code And still, the method is defined in the environment: ### R code > showMethods("[", class="genind") Function: [ (package base) x="genind" > findMethods("[", classes="genind")$genind Method Definition: function (x, i, j, ..., drop = FALSE) { .local <- function (x, i, j, ..., loc = NULL, treatOther = TRUE, drop = FALSE) { if (missing(i)) i <- TRUE if (missing(j)) j <- TRUE pop <- NULL ... # rest of the code of the function ### end R code findMethods and showMethods find the method. However, getMethod doesn't: ### R code > getMethod("[","genind") Error in getMethod("[", "genind") : No method found for function "[" and signature genind ### end R code Now, if I just try the same thing after sourcing the code of the method manually, everything works fine. showMethods then reads: ### R code > showMethods("[", classes="genind") Function: [ (package base) x="genind" x="genind", i="ANY", j="ANY", drop="ANY" x="genind", i="numeric", j="missing", drop="missing" (inherited from: x="genind", i="ANY", j="ANY", drop="ANY") ### end R code My R version/session is: ### R code > R.version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 11.0 year 2010 month 04 day 22 svn rev 51801 language R version.string R version 2.11.0 (2010-04-22) > sessionInfo() R version 2.11.0 (2010-04-22) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.utf8 LC_NUMERIC=C [3] LC_TIME=en_GB.utf8 LC_COLLATE=en_GB.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.utf8 [7] LC_PAPER=en_GB.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] adegenet_1.2-4 MASS_7.3-5 loaded via a namespace (and not attached): [1] graph_1.26.0 phylobase_0.5 tcltk_2.11.0 tools_2.11.0 ### end R code R was compiled from the sources. All packages are up-to-date (as of the 21 May 2010). My system is a Ubuntu 10.04 (32 bits), with kernel 2.6.31-20-generic. I could not reproduce the problem using R 2.11.0 on Windows Vista, or on Debian testing (R 2.11.0 compiled from the sources). The package adegenet does not have a namespace. The error arises whether using a field 'Collate' in DESCRIPTION, or not. I checked that the source file is indeed sourced when loading the package: it is. The method "[" is not defined by any other package for 'genind' objects. I would be pleased to get any piece of insight, advice, or explanation for this issue. Thanks in advance for your time. Best regards, Thibaut Jombart. -- ###################################### Dr Thibaut JOMBART MRC Centre for Outbreak Analysis and Modelling Department of Infectious Disease Epidemiology Imperial College - Faculty of Medicine St Mary’s Campus Norfolk Place London W2 1PG United Kingdom Tel. : 0044 (0)20 7594 3658 t.jomb...@imperial.ac.uk http://sites.google.com/site/thibautjombart/ http://adegenet.r-forge.r-project.org/ ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel