I have a function that produces a function:
fun1 <- function (x)
return (function() x)
By the time a function is produced, the value of x
is already basically a constant:
fun2 <- fun1 ("a")
However, when I have fun2
printed, it won't show the actual value, it only shows "x"
even though it is by now obsolete:
> fun2
function() x
<environment: 0x55a9f94f9fc8>
How can I force the evaluation of x
so that fun2
gets printed as
function() "a"
or however it was produced?
There's no need to resort to
deparse
here. You can write the evaluated value of x into the body of the newly created function:So that:
and
EDIT
If you wanted
f
to take an argument you could do:so that