Suppose I have:
test <- function(x) x + 1
test
function(x)
x + 1
I would like to somehow save the output produced by invoking test
to a string (i.e. the function declaration) but can't think of a way to do it.
We can use deparse
paste(deparse(test), collapse = " ")
#[1] "function (x) x + 1"
Also, if we need to extract the components of the function, use body
body(test)
Or split it to a list
as.list(test)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With