Consider the example below:
> x=2
> myfun = function(y) x*y
> myfun(3)
[1] 6
> x=4
> myfun(3)
[1] 12
How would I have to define myfun
so that its definition keeps the value of x
such as it is at the time of definition, rather than a reference to x
? (i.e., that the second call myfun(3)
also yields 6 rather than 12).
EDIT: changed the title to remove incorrect terminology.