Closed petermeissner closed 7 years ago
I'm reasonable certain you should simply not set parent_env
. If you call parent.frame()
from the top-level (as you are), it returns global_env()
.
Me again ... because I ran into this again ... this time from a slightly other angle.
R6::R6Class()
parent_env = parent.frame()
is the default setting and not setting the parameter will not change behaviour?. could not find function "..."
) occur when writing a package and using unexported functions from that package - without explicitly using: parent_env = asNamespace('mypackage')
... I think this problem can occur reasonable often and is reasonable hard to understand / find a solution for to maybe get reconsidered / mentioned in documentation
Gist:
This is _not a bug but merly the request to add a sentence to the documentation of
R6Class()
mentioning that sometimes **"for inheriting classes set \code{parentenv} to e.g. \code{asNamespace('mypackage')} to get access to the package's unexported functions"**Long format:
I stumbled about this problem building a package looking something like this:
Now the problem is that -- when building a package like that -- an instance of the sub class will not be able to find
my_function()
:Thinking about it and doing some research it is clear, that it has to work that way since the instance is looking for
my_function()
withinsuper_class
but actually it is to be found withinmypackage
- right?The solution (thanks to Mark and Thomas) is to e.g. use the
parent_env
argument ofR6Class ()
so thatmy_function()
can be found, e.g. setting it to the package environment: