Conner M.
Conner M.

Reputation: 2074

R - How to format list of methods in Reference Class?

I have a more complicated Reference Class that I've whittled down to the code below:

make_LD <- setRefClass("Longitudinal_Data",
                       methods = list(
                         populator <- function() {
                           print("Working")
                         }))
make_LD$populator()

Error in envRefInferField(x, what, getClass(class(x)), selfEnv) : 
  ‘populator’ is not a valid field or method name for reference class “refGeneratorSlot”

But getting the above error. It's not clear to me at all what I'm missing. The method populator shows up under make_LD$methods() but not under make_LD$getClass(). I've tried several different variable names for the method.

Upvotes: 0

Views: 560

Answers (1)

M.F
M.F

Reputation: 109

make_LD is a constructor! You use it to make an object and you can then use that object.
To check, use this code

make_LD <- setRefClass("make_LD",
                       methods = list(
                         populator = function() {
                           print("Working")
                         }
                       ))
mkld <- make_LD()
mkld$populator()

Upvotes: 1

Related Questions