I'd like to define a function f
from parameters and an expression that are character
strings read from a .csv
file.
This function f
has the following expression :
f = function( parameters ) { expression }
where parameters are a list of n parameters and the expression is a function of these parameters.
For example: the parameters are x1
,x2
,x3
, and expression is (x1+x2)*x3
.
The function f
is then f = function(x1,x2,x3){ (x1+x2)*x3 }
.
How I proceed in R to define such functions ?
EDIT add more context:
Given 2 charcaters strings , for body and arguments
body="(x1+x2)*x3"
args = "x1,x2,x3"
How we can get ?:
function (x1, x2, x3)
(x1 + x2) * x3
Note that this question is similar but don't answer exactly this one, since the solution proposed don't create the function formals (arguments) from a character string.