Closed yonicd closed 5 years ago
Any members of Simple
that are functions are considered methods, and so they'll have their environment changed when an object of class Simple is instantiated.
If you want to work around this, you can either:
Assign foo
in the initialize
method:
Simple <- R6::R6Class("Simple",
public = list(
initialize = function() {
self$foo <- stats::rbinom
},
foo = NULL
)
)
Make foo
a wrapper function that calls the function you want.
Simple <- R6::R6Class("Simple",
public = list(
foo = function(...) stats::rbinom(...)
)
)
In this case I think it makes more sense to use the second option.
I am trying to place a function from a installed package using
set
, in the example belowstats::rbinom
.the function's environment is replaced when initializing on the R6 class. This causes the runction itself not to be able to run since it can't locate non exported functions from the parent namespace.
Is there a simple way to do this in R6?
Created on 2018-10-12 by the reprex package (v0.2.1)