[datatable-help] Passing i, j and by to dt() as characters

Matthew Dowle mdowle at mdowle.plus.com
Fri Apr 13 10:21:42 CEST 2012


Interesting.

by accepts a 'single character string containing comma separated column
names', so by="e,f" in this case could be passed straight through.
Passing expressions (using quote()) to i,j and by is another idiom, see
FAQ 1.6.
But in this case where it's a URL interface that you're providing, I'm
thinking it's probably easier and simpler to: 
eval(parse(text=paste("dt[",...)))? Maybe wrap that idiom into a helper
function with a shorter name if you do it a lot. Also use paste0 rather
than paste, new in R 2.15.0.

Can't let that 'i' (f1=="a" & f2=="b") go without a comment. With 3 vector
scans and allocations it's almost heresy to data tablers! Could dt be
keyed by (f1,f2) then do dt[J("a","b"),...]? If you don't know in advance
which columns, and the key would vary a lot, would secondary keys be
something that would help you a lot?  Perhaps data.table could get fancy
with vector scanning i expressions and automatically convert them to use
keys.

Matthew

> Hello,
>
> I apologize in advance if this has been covered before, but I'm trying to
> write a generic function that takes 3 URL parameters of the form:
>
> http://my.url?param1='f1=a,f2=b'&param2='c,d'&param3='e,f'
>
> and simply pass them to dt(), so the expression to evaluate is:
>
> dt[f1=="a" & f2=="b", list( t1(c), t2(d) ), by=list( e, f )]
>
> where t1, t2 are custom aggregation functions.
>
> I can't seem to find an elegant way to convert the strings to vector
> names.
> Using .SDcols does work for the elements in j, but what about i and by?
>
> Any tip would be very helpful!
> Thanks, --Mel.
>
> _______________________
>  Melanie Bacou
>  IFPRI / HarvestChoice
>  Washington DC, 20006
>  W +1(202)862-5699
>  C +1(202)492-7978
>  m.bacou at cgiar.org 
>
>
> _______________________________________________
> 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
>




More information about the datatable-help mailing list