evaluate R command using eval, parse and paste

Post date: Mar 27, 2014 6:53:29 PM

When you need to evaluate a command, eval, parse and paste will come together in the format below:

eval(parse(text="your command here"))   my.var.name <- 'bot' my.value <- 500  eval(parse(text=paste(my.var.name,"=",my.value, sep=""))) > bot [1] 500

This is a good example of assigning and accessing the list via variable from https://stat.ethz.ch/pipermail/r-help/2011-March/272790.html

my.list <- list(Tom=c(1,2,3), Dick=c(4,5,6), Harry=c(7,8,9)) myname <- "Harry" my.list[[myname]]  ## extract   my.list[[myname]] <- 11:13 ## assign my.list[[myname]] ## extract