Suppose I have the following function:
g = function(x) x+h
Now, if I have an object with a name in my environment h
, I would not have a problem:
h = 4
g(2)
Now I have another function:
f = function() {
h = 3
g(2)
}
I would expect:
rm(h)
f()
#
Instead, I get an error message
#
I would expect it to g
be evaluated in the environment f
, so that h
in f
will be attached to h in g, as it was when I performed g
within .GlobalEnv
. This does not happen (obviously). any explanation why? how to overcome this so that the function inside the function (for example g
) is evaluated using the environment?
source
share