get.var.RdThis routine takes a text string and a data frame or list. It first sees if the
string is the name of a variable in the data frame/ list. If it is then the value of this variable is returned.
Otherwise the routine tries to evaluate the expression within the data.frame/list (but nowhere else) and if
successful returns the result. If neither step works then NULL is returned. The routine is useful for
processing gam formulae. If the variable is a matrix then it is coerced to a numeric vector, by default.
get.var(txt,data,vecMat=TRUE)The evaluated variable or NULL. May be coerced to a numeric vector if it's a matrix.
require(mgcv)
y <- 1:4;dat<-data.frame(x=5:10)
get.var("x",dat)
#> [1] 5 6 7 8 9 10
get.var("y",dat)
#> NULL
get.var("x==6",dat)
#> NULL
dat <- list(X=matrix(1:6,3,2))
get.var("X",dat)
#> [1] 1 2 3 4 5 6
#> attr(,"matrix")
#> [1] TRUE