[Rd] dumpMethod/getMethod on methods in packages

Kasper Daniel Hansen khansen at stat.berkeley.edu
Mon Dec 14 22:42:24 CET 2009


There seems to be something wrong with dumpMethod when called on methods defined in packages (possibly with namespaces).  This may be caused by a possible bug in getMethod.

(see below for a full copy/paste without comments)

First
library(Matrix)

Now compare
  dumpMethod("rowSums", "ngCMatrix", file = "")  ## Nothing
to
  getMethod("rowSums", "ngCMatrix")  ## The method definition

Further inspection suggests that it is related to the where argument to dumpMethod, the default being where = topenv(parent.frame()) which evaluates (in this usecase) to .GlobalEnv.  I find it interesting to compare
  findMethod("rowSums", "ngCMatrix", where = .GlobalEnv)  ## Finds the method in the Matrix package
to
  getMethod("rowSums", "ngCMatrix", where = .GlobalEnv)  ## Does not find anything

It seems to me that getMethod is wrong when it does not find anything in the global environment.

Tested in R-2.10-patched (r50736) and R-devel (r50736)

dumpMethod works fine with example(dumpMethod) where a method gets defined in the global environment.  My usecase was trying to dump a method from a namespace I had edited with trace(..., edit = TRUE)

Kasper

All 5 lines for copy and paste:

library(Matrix)
dumpMethod("rowSums", "ngCMatrix", file = "")
getMethod("rowSums", "ngCMatrix")
findMethod("rowSums", "ngCMatrix", where = .GlobalEnv)
getMethod("rowSums", "ngCMatrix", where = .GlobalEnv)



More information about the R-devel mailing list