Hervé Pagès
2009-Jul-07 00:25 UTC
[Rd] Protection stack overflow when calling setGeneric()/setMethod() from within .onLoad()
Hi list, Calling setGeneric()/setMethod() from within the .onLoad() hook of MyPkg package produces the following error: > gctorture(TRUE) > library(MyPkg) .onLoad(): ok1 .onLoad(): ok2 Error : protect(): protection stack overflow Error : .onLoad failed in 'loadNamespace' for 'MyPkg' Error: package/namespace load failed for 'MyPkg' This is with the following code in the .onLoad() hook: .onLoad <- function(libname, pkgname) { cat(".onLoad(): ok1\n") setGeneric("foo", function(x, y) standardGeneric("foo")) cat(".onLoad(): ok2\n") setMethod("foo", c("ANY", "ANY"), function(x, y) cat("calling foo,ANY,ANY method\n") ) cat(".onLoad(): ok3\n") } and with R-2.9.0/R-2.9.1 or recent R-devel. Note that without the call to gctorture(TRUE), everything *seems* to work fine: > library(MyPkg) .onLoad(): ok1 .onLoad(): ok2 .onLoad(): ok3 but it could be that my session is now corrupted because some users have reported the nasty and now famous: Error in get(name, envir = table) : formal argument "envir" matched by multiple actual arguments Calls: assign ... .getGeneric -> .cacheGeneric -> .cacheGenericTable -> get after they've loaded MyPkg and started to run some other code that is not necessarily calling foo(). Those users are running R-2.9.1 or a very recent R-devel (less than 1 week old) so they are not triggering the reg.finalizer() problem reported here (and fixed) a few weeks ago: https://stat.ethz.ch/pipermail/r-devel/2009-June/053607.html Also note that if I make foo() a function of one argument only, I don't get the protection stack overflow anymore. Cheers, H. -- Herv? Pag?s Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319