I'm trying to make a small R package with my limited knowledge in R programming. I am trying to use the following argument:
The question is not completely clear so we will assume that the question is, given a formula using standard formula syntax, how do we parse out the variables names (or in the second answer the variable names and constants) giving as output a character vector containing them.
1) all.vars Try this:
fo <- a + b * X # input all.vars(fo)
 "a" "b" "X"
2) strapplyc Also we could do it with string manipulation. In this case it also parses out the constants.
library(gsubfn) fo <- ~ 25 + 35 * X # input strapplyc(gsub(" ", "", format(fo)), "-?[0-9.]+|[a-zA-Z0-9._]+", simplify = unlist)
 "25" "35" "X"
Note: If all you are trying to do is to evaluate the RHS of the formula as an R expression then it is just:
X <- 1:3 fo <- ~ 1 + 2 * X eval(fo[])
 3 5 7
Update: Fixed and added second solution and Note.