Expression evaluation
Assign and retrieve variables on the fly
Assign/Get
The assign() function is the equivalent of the arrow '<-' operator.
assign("x", mean(runif(10)))
get("x")
## [1] 0.5767
patientid <- "10"
assign(paste0("treatment", patientid), sample(c("control", "treatment"), 1))
treatment10
## [1] "treatment"
Eval
This function is able to evaluate a character string as if it was direct R code.
eval(parse(text=paste0("i <- ", "\"lots lots lots\"")))
i
## [1] "lots lots lots"

This work by Celine Hernandez is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.