Skip to content
Prev 51332 / 63424 Next

How do I reliably and efficiently hash a function?

On Thu, 10 Dec 2015, Konrad Rudolph wrote:

            
See

https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Scope

For example, these commands:

foo <- function() {info <- "abc";function(x) x+1}
func <- foo()
find("func")
func(1)
ls(envir=environment(func))
get("info",environment(func))
func

Yield these printed results:

: [1] ".GlobalEnv"
: [1] 2
: [1] "info"
: [1] "abc"
: function (x)
: x + 1
: <environment: 0x7fbd5c86bc60>

The environment of the function gets printed, but 'info' and other
objects that might exist in that environment do not get printed unless
you explicitly call for them.

HTH,

Chuck

p.s. 'environment(func)$info' also works.