[R] "use of NULL environment is defunct" when trying to lock a reference class

Eric Berger er|cjberger @end|ng |rom gm@||@com
Mon Aug 27 20:48:50 CEST 2018


Hi Ivan,
Unfortunately I cannot answer your question.
However, I do have quite a bit of experience using R's reference classes
and you might want to consider the more recent R6 package.
It provides R6 classes which have advantages over
reference classes.  See for example:

1. Hadley Wickham on R6 (chapter 16 in "Advanced R")
https://adv-r.hadley.nz/r6.html

2. The R6 package documentation which seems to mention 'lock' in quite a
few places
https://cran.r-project.org/web/packages/R6/R6.pdf

HTH,
Eric


On Mon, Aug 27, 2018 at 7:25 PM, Ivan Krylov <krylov.r00t using gmail.com> wrote:

> Hi!
>
> I'm trying to create a persistent memoising class with a destructor and
> an option to evaluate cache misses in parallel. I want to lock all
> its fields because it doesn't make sense to change them after the
> filename, the environment object and the function are set in the
> object. (I'm not sure whether I should lock the environment field I use
> as the hash, though.)
>
> The problem is, I can't figure out how to use class$lock(...) properly:
>
> > test.class <- setRefClass("test", fields=c("field"))
> > test.class$lock("field")
> Error in .makeDefaultBinding(current using field, current using className, TRUE,
> environment(current)) :
>   use of NULL environment is defunct
>
> By looking at traceback() and source of methods:::.lockRefFields,
> I see that environment(zzz using generator$def using fieldPrototypes[["field"]])
> is, indeed, NULL.
>
> I'm using R version 3.3.3 (2017-03-06),  version$`svn rev` is "72310".
>
> What am I doing wring?
>
> --
> Best regards,
> Ivan
>
> P.S. Please Cc me in your replies to the list, if possible.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]




More information about the R-help mailing list