A side note on Matthew's last 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"),...]?"

Matthew is, of course, right. (As the god of data.table, he better be!) 
However, not all data tables contain lots of data, and in such a case I would 
probable use Mel's code for its simplicity. 

Please do not burn this heretic at the stake!

Joe


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of 
Matthew Dowle
Sent: Friday, April 13, 2012 4:22 AM
To: [email protected]
Cc: [email protected]
Subject: Re: [datatable-help] Passing i, j and by to dt() as characters


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
>  [email protected]
>
>
> _______________________________________________
> datatable-help mailing list
> [email protected]
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable
> -help
>


_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to