[R] Force evaluation of variable when calling partialPlot

Ben Bond-Lamberty
Mon, 04 Oct 2010 12:37:13 -0000

Dear R Users,

I'm using the randomForest package and would like to generate partial
dependence plots, one after another, for a variety of variables:

m <- randomForest( s, ... )
varnames <- c( "var1", "var2", "var3",
"var4" )   # var1..4 are all in
data frame s
for( v in varnames ) {
   partialPlot( x=m, pred.data=s, x.var=v )
}

...but this doesn't work, with partialPlot complaining that it can't
find the variable "v". I think I need to force the evaluation of the
loop variable v so that partialPlot sees the correct variable names,
but am stumped after trying eval and similar functions. Any
suggestions on how to do this? Googling has not turned up anything
very useful.

Thanks,
Ben