[datatable-help] In R data.table, how do I pass variable parameters to an expression?

Jitender jitender.aswani at gmail.com
Sun May 20 18:34:43 CEST 2012


I am stuck with a small R issue with data.table. Your help is much
appreciated. How do I do this:

get <- function(dt, expr, gby) {
  e <- substitute(expr)
  b <- substitute(gby)
  return(dt[,eval(e),by=b])
}

v1 <- "Sepal.Length"
v2 <- "Species"

dt <- data.table(iris)
rDT <- get(dt, sum(v1, na.rm=TRUE), v2)

I get following error: Error in sum(v1, na.rm = TRUE) : invalid 'type'
(character) of argument

Now, both v1 and v2 get passed from other program as character variable so
I can't do this v1<- quote(Sepal.Length) which seems to work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120520/dc01708f/attachment-0001.html>


More information about the datatable-help mailing list