In the answer found here we have an original function.
myfun <- function(x,y) {
result <- list(x+y,x*y)
return(result)
}
They replace the second line of the function with result <- list(2 * x, x * y)
by running:
body(myfun)[[2]][[3]][[2]] <- substitute(2*x)
What I am looking to do is add a line to the function instead of replacing to get something like:
myfun <- function(x,y) {
print(x)
result <- list(x+y,x*y)
return(result)
}
Is this possible? I have tried a whole raft of substitute
, bquote
, eval
, parse
, quote
, and expression
commands.