Skip to content
Prev 367108 / 398525 Next

Help with saving user defined functions

It worked fine for me:
[1] 1.042457
[1] 0.1117773


Of course, if I remove cdf() from the global environment, it will fail:
Error in qnorm(cdf(x) * 0.99) : could not find function "cdf"

So it looks like you're clearing you global workspace in between
saving and loading?

You may need to read up on function closures/lexical scoping : A
user-defined function in R includes not only code but also a pointer
to the environment in which it was defined, in your case, the global
environment from which you apparently removed cdf(). Note that
functions are not evauated until called, so free variables in the
functions that do not or will not exist in the function's lexical
scope when called will not trigger any errors until the function *is*
called.

Same comments for your second version -- if tmp is removed the
function will fail.



Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Feb 12, 2017 at 2:11 PM, George Trojan - NOAA Federal
<george.trojan at noaa.gov> wrote: