Skip to content
Prev 278307 / 398502 Next

evaluation question

On Nov 23, 2011, at 00:24 , Rolf Turner wrote:

            
The fortune does say "usually", and there certainly are exceptions, for instance the use in Rcmdr where you edit and submit code from the log window.

What to avoid is something like this:

value <- 3.2; r <- 1
cmd <- paste("pexp(",value,",rate=",r,")")
eval(parse(text=cmd))

where  

pexp(value,rate=r)

would do. Or, if you do need the unevaluated expression:

bquote(pexp(.(value),rate=.(r)))

(I believe we still have a couple of cases in the standard R code where the code does something like

rhs <- paste(vnames, sep="+")

and then proceeds to parse it and put the result into the right hand side of a model formula. It works (mostly) but it hurts my eyes seeing computing on the language done via the textual representation.)