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

Christoph Jäckel christoph.jaeckel at wi.tum.de
Sun May 20 21:00:49 CEST 2012


You also posted this on stackoverflow (
http://stackoverflow.com/questions/10675182/in-r-data-table-how-do-i-pass-variable-parameters-to-an-expression),
so there is no need to post it here as well. I think the answers there are
already helpful.

On Sun, May 20, 2012 at 6:34 PM, Jitender <jitender.aswani at gmail.com> wrote:

>  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.
>
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120520/c4ce9188/attachment-0001.html>


More information about the datatable-help mailing list