From mtmorgan at fhcrc.org  Thu Dec  8 23:52:54 2011
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Thu, 08 Dec 2011 14:52:54 -0800
Subject: [Rd] Reference class finalize() fails with 'attempt to apply
	non-function'
Message-ID: <4EE13FC6.5070606@fhcrc.org>

This bug appears intermittently in R CMD check when reference classes 
have finalize methods. The problem is that garbage collection can be run 
after the methods package is no longer available. It affects 
(periodically) the Bioconductor AnnotationDbi package as well as 
packages that contain Rcpp classes. To reproduce:

   library(methods)
   a = setRefClass("A", methods=list(finalize=function() cat("A\n")))
   b = setRefClass("B", contains="A")

repeat b = setRefClass("B", contains="A") until finalize does not run 
(no garbage collection triggered during setRefClass)

   b = setRefClass("B", contains="A")
   b = setRefClass("B", contains="A")

and then

 > detach("package:methods")
 > gc()
Error in function (x)  : attempt to apply non-function
Error in function (x)  : attempt to apply non-function

 > traceback()
1: function (x)
    x$.self$finalize()(<environment>)

I believe a variant of the same type of problem generates an error

Error in function (x)  : no function to return from, jumping to top level

also seen in AnnotationDbi and Rcpp packages
-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



[Rd] Reference class finalize() fails with 'attempt to apply non-function'
Martin Morgan