Has anyone converted a function in R into a string or text object?
Let's say for a simple square function, I'd want to convert to a text file:
sqfxn <- function(x){
# Get square of x
# Expect:
# > sqfxn(2)
# > 4
output <- x^2
return(output)
}
Is there a function that will convert sqfxn()
to a string object?
fxn_to_text <- function(x){
# convert function x to text
}
Which will result to:
> txt_fxn <- fxn_to_txt(sqfxn)
> print(txt_fxn)
> "function(x){
# Get square of x
# Expect:
# > sqfxn(2)
# > 4
output <- x^2
return(output)
}"
Thanks!