Skip to content
Prev 45467 / 63421 Next

Ref classes initFields has incorrect environment?

As suggested by the following code:

A <- setRefClass("A", fields = list(x = "logical"),
  methods = list(initialize = function(...) {
    x <<- FALSE
    initFields(...)
}))
A$new()
# Works as expected

quote <- as.character
A$new()
# Error in function (value)  :
#  invalid replacement for field ?x?, should be from class ?logical?
or a subclass (was class ?character?)

I get the same error in:
* R version 2.15.2 (2012-10-26)
* R version 2.15.3 (2013-03-01)
* R Under development (unstable) (2013-03-28 r62432)

Hadley