Here are some ways to pass variables by reference and paste them into the Call formula. The first line is copied from @Richard Scriven function
fun1 <- function(n1, n2){ form1 <- as.formula(paste("class~", paste(n1, n2, sep = "+"))) do.call("svm", list(form1, quote(df))) } fun1(name1, name2)
or
fun2 <- function(n1, n2){ form1 <- as.formula(paste("class~", paste(n1, n2, sep="+"))) eval(substitute(svm(f, df), list(f = form1))) } fun2(name1, name2)
Or you can pass the @Rchard Scriven function as an argument in fun3
fun2New <- function(n1, n2){ as.formula(paste("class~", paste(n1, n2, sep="+"))) } fun3 <- function(formula, data, ...){ Call <- match.call(expand.dots = TRUE) Call[[1]] <- as.name("svm") Call$formula <- as.formula(terms(formula)) eval(Call) } fun3(fun2New(name1, name2), df)
akrun Sep 21 '14 at 7:39 2014-09-21 07:39
source share