[datatable-help] suggestion for transform.data.table.Rd

G See gsee000 at gmail.com
Tue Oct 16 14:54:20 CEST 2012


One other small thing in the docs along these lines:  Now that
assignment by reference does not print by default, the last few
examples in ?data.table kind of lose something.

e.g. instead of
    DT[, z:=42L]

maybe make it one of these?
    DT[, z:=42][]
    (DT[, z:=42L])
    print(DT[, z:=42L])
    DT[, z:=42L]; DT

Best,
Garrett

On Tue, Oct 16, 2012 at 4:40 AM, Matthew Dowle <mdowle at mdowle.plus.com> wrote:
>
> Well spotted, thanks. Will do. Filed as #2316 linking back to this thread.
>
> And will include this in ?transform.data.table :
>
>     dt[, transform(.SD, c=max(b)), by="a"]
>     dt[, c:=max(b), by="a"]   # same, but much much faster
>
> Btw, just to highlight to all that `:=`() is working, and by group, in
> 1.8.3 now. This makes multiple := by group particularly elegant. Thanks to
> Thell Fowler for the suggestion.
>
> DT[, `:=`(newcol1:=max(a),
>           newcol2:=min(b),
>           existingcol:=max(c),
>           newcol3:=mean(a)), by=grp]
>
> Rather than multiple LHS and having to set with=FALSE, which also now
> works by group and you no longer need with=FALSE. But `:=`(...) gets each
> LHS and RHS together on one line in pairs, so makes it easier to read.
>
> For people who have joined the list recently, the latest
> info/documentation is always in NEWS first. It usually takes a version or
> two for it to be fleshed out in the help files. "NEWS" is considered
> documentation :
>
> https://r-forge.r-project.org/scm/viewvc.php/pkg/NEWS?view=markup&root=datatable
>
>
>> It was not clear to me from the help page when I should use
>> `transform` or `within` instead of `:=`.
>>
>> May I suggest copying the following comment (found in data.table.R) to
>> the help page?
>>
>> # `within` and other similar functions in data.table are
>> # not just provided for users who expect them to work, or
>> # prefer syntax they're used to, but for non-data.table-aware
>> # packages to retain keys (for example). Hopefully users and
>> # code will use the faster data.table syntax in time.
>>
>> Also, the examples section of ?transform.data.table has the following
>> commented out "example"
>>
>>     # dt[, transform, c = max(b), by="a"]  # like "ave"
>>
>> If run, this will give an error
>>     Error in `[.data.table`(dt, , transform, c = max(b), by = "a") :
>>       unused argument(s) (c = max(b))
>>
>> Based on test 104, I think that should be changed to
>>
>>     dt[, transform(.SD, c=max(b)), by="a"]
>>
>> Best,
>> Garrett
>> _______________________________________________
>> 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