Try eval(parse(text=...)) or eval(substitute(...)) .
parse(text=...) turns the string into an expression, eval evaluates the expression. Be sure to use the text argument, as parse usually looks for a file. Forgetting it is a common mistake. See also ?parse and ?eval .
> a <- 10 > x <- deparse(substitute(a)) > eval(parse(text=x)) [1] 10
To show how to use it, customized code:
for(i in 1:10) eval(parse(text=paste("rp.slider(rpplot,param",i,")",sep="")))
substitute replaces the values ββin the language object with the lines specified in the second argument:
for(i in 1:10) eval( substitute( rp.slider(rpplot,x), list(x=as.name(paste("param",i,sep=""))) ) )
Or using the example in the help files:
library(rpanel) rpplot <- rp.control(title = "Demonstration of rp.tkrplot", h = 1,j=1) redraw <- function(panel) { rp.tkrreplot(panel, tkrp) } x <- c('h','j') rp.tkrplot(rpplot, tkrp, function(panel) plot((1:20)^panel$j, (1:20)^panel$h)) eval(parse(text=paste("rp.slider(rpplot, ",x[1]," , action = redraw, from = 0.05, to = 2.00, resolution = 0.05)"))) eval( substitute( rp.slider(rpplot, x, action=redraw, from=0.05, to=2.00, resolution=0.05), list(x = as.name(x[2])) ) )
An explanation of why this is necessary can be found in the source code of rp.slider. The construct for getting varname inside a function is not the standard used in R. Actually, the use of "deparse (substitute ())" is strongly discouraged, for this very reason. In most functions, as.expression("x") works to get the variable by using the variable name. Alas, the author of the rpanel package made this impossible.