Skip to content
Prev 7480 / 12125 Next

[R-pkg-devel] Is there a better way ...?

On 21/10/2021 12:40 a.m., Andrew Simmons wrote:
I agree with the final result, but I'd write the code differently:

plot.foo <- local({

   .fooInfo <- NULL

   function (...) { ... }
})

creates an environment, puts .fooInfo into it with value NULL, then 
creates a function with that environment attached and returns it.

I think Andrew's approach will work, but changing a function's 
environment always worries me.  Using local(), the function assigned to 
plot.foo never has a different environment than the one it ends up with 
(and I don't need to remember how evalq() works).

Duncan Murdoch