Skip to content
Prev 67782 / 398506 Next

Define "local" function

Ales Ziberna <ales.ziberna at guest.arnes.si> writes:
Notice BTW, that environment(f) <- NULL may have unexpected
consequences. What it really means is that the lexical scope of f
becomes the base package. This interpretation of NULL may change in
the future, since it is somewhat illogical and it has a couple of
undesirable consequences that there's no way to specify a truly empty
environment. So

a) if you're calling a function outside of the base package, you get
the effect of
Error in mean(rnorm(10)) : couldn't find function "rnorm"

b) even if it does work now, it may be broken by a future change to R.
Notice that *all* functions contain unbound variables in the form of
functions so if we get an empty NULL environment, even "<-" may stop
working.