Reputation: 175
I want to write a function. However, the assumption is that I don't know the input arguments of the function. I just have a character vector to define input arguments of the function. Consider the following code:
f <- expression(exp(-d^2/s^2) )
fx <- function(d, s){ eval( f[[1]] ) }
In the above code, I know the parameters of expression
and easily define a calculative function for it. But I get the expression from the user and I don't know what are the parameters. So, I want something like this:
f <- expression(exp(-d^2/s^2) )
v = all.vars(f)
#"d" "s"
fx <- function(?){ eval( f[[1]] ) }
I want to convert v
to d
and s
on input function instead of ?
. Is there any way?
Upvotes: 1
Views: 247