[datatable-help] lapply without anonymous function

Arunkumar Srinivasan aragorn168b at gmail.com
Mon Aug 4 01:57:50 CEST 2014


GSee and List,

With commit 1336, this now works:

require(data.table)
L = list(as.data.table(BOD), as.data.table(BOD))
lapply(L, "[", Time == 3L)
Please write back if you come across any issues.


Arun

From: G See <gsee000 at gmail.com>
Reply: G See <gsee000 at gmail.com>>
Date: November 11, 2013 at 3:40:46 PM
To: Gabor Grothendieck <ggrothendieck at gmail.com>>
Cc: datatable-help at lists.r-forge.r-project.org <datatable-help at lists.r-forge.r-project.org>>
Subject:  Re: [datatable-help] lapply without anonymous function  

heh, after all my efforts to avoid subset(), it can be useful after all. :)  

Bug report filed, per Eduard's suggestion.  

On Mon, Nov 11, 2013 at 8:06 AM, Gabor Grothendieck  
<ggrothendieck at gmail.com> wrote:  
> On Sun, Nov 10, 2013 at 2:39 PM, G See <gsee000 at gmail.com> wrote:  
>> Hi,  
>>  
>> I have a list of data.tables and I am trying to extract a subset from  
>> each of them. I can achieve what I want with this:  
>>  
>>> L <- list(data.table(BOD), data.table(BOD))  
>>> lapply(L, function(x) x[Time==3L])  
>> [[1]]  
>> Time demand  
>> 1: 3 19  
>>  
>> [[2]]  
>> Time demand  
>> 1: 3 19  
>>  
>> However, I'd rather not type have to create an anonymous function. I  
>> tried the below, but `[.data.frame` is being dispatched.  
>>  
>>> lapply(L, "[", Time==3L)  
>> Error in `[.data.frame`(x, i) : object 'Time' not found  
>>  
>> Even if I am explicit, `[.data.table` does not get dispatched:  
>>  
>>> lapply(L, data.table:::`[.data.table`, Time==3L)  
>> Error in `[.data.frame`(x, i) : object 'Time' not found  
>>  
>> I'm guessing this is due to where evaluation takes place. Is there an  
>> alternate syntax I should use?  
>>  
>  
> subset works:  
>  
>> lapply(L, subset, Time == 3L)  
> [[1]]  
> Time demand  
> 1: 3 19  
>  
> [[2]]  
> Time demand  
> 1: 3 19  
>  
>  
>  
> --  
> Statistics & Software Consulting  
> GKX Group, GKX Associates Inc.  
> tel: 1-877-GKX-GROUP  
> email: ggrothendieck at gmail.com  
_______________________________________________  
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/20140804/ae4a93d9/attachment.html>


More information about the datatable-help mailing list