Is there a way, to change the execution environment of a non-exported function defined in package's namespace?
My goal is to swiftly force this function to follow different scoping path to invoke some custom methods/objects (defined in the new environment), without the need of duplicating the whole package. Currently, I'm unsuccessful with
> environment(ggplot2:::create_layout)
<environment: namespace:ggplot2>
> env <- new.env()
> parent.env(env) <- asNamespace('ggplot2')
> environment(ggplot2:::create_layout) <- new.env
Error in environment(ggplot2:::create_layout) <- new.env :
object 'ggplot2' not found
In this specific example i would like create_layout
to use a modified version of ggplot2
's ggproto
function and Layer
object present in the env
environment. My logic was that changing the searching scope is less messy, than modifying the object's body inside the namespace.