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

From: Dan Tenenbaum <dtenenba_at_fhcrc.org>
Date: Thu, 29 Dec 2011 11:35:25 -0800

On Thu, Dec 8, 2011 at 2:52 PM, Martin Morgan <mtmorgan_at_fhcrc.org> wrote:
> 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

Here is a self-contained reproducible example that immediately and consistently produces the error on R 2.14 and R-devel:

library(methods)
a = setRefClass("A",
  methods=list(finalize=function() options("finalized"=TRUE))) b = setRefClass("B", contains="A")

while (TRUE) {

    options("finalized" = FALSE)
    b = setRefClass("B", contains="A")
    if (!getOption("finalized")) break
}

detach("package:methods")
gc()

Thanks!
Dan

> --
> Computational Biology
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
>
> Location: M1-B861
> Telephone: 206 667-2793
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 29 Dec 2011 - 19:37:38 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 Dec 2011 - 22:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive