[datatable-help] Integration with magrittr

Michael Smith my.r.help at gmail.com
Thu Jul 2 03:25:45 CEST 2015


Hi Steve,

Okay glad to hear we're on the same page and thanks for your thoughts 
and views. You're right, we're in "personal taste" land and what is 
"better" is subjective here.

What I had in mind was exactly what you've mentioned, i.e. to parse 
LHS%<>%RHS as LHS:=LHS%>%RHS in data.table before evaluating.

In my mind, that should not be so difficult to do, since `:=` is already 
implemented. But maybe I'm wrong and it's difficult to do (I still 
should finish reading Hadley's chapters on metaprogramming in his 
"Advanced R" book.) Would also be interesting to hear Matthew's or 
Arun's opinions.

Cheers,
M

On 07/02/2015 12:47 AM, Steve Lianoglou wrote:
> Hi Michael
>
>> Maybe I have not pointed this out clearly enough and I'm sorry about that,
>> but my point is NOT how to multiply a number by two.
>
> No -- I knew you were giving a shorter example for something that
> might be more complicated ... I mentioned that I couldn't imagine a
> "not contrived" example where this would really be a win, but I'll
> grant you that we are in a very subjective realm now.
>
>> This calculation could IN REALITY be of course more complicated than *2, and
>> could involve many functions chained together and a long variable name that
>
> These were the types of scenarios I was trying to think of as well.
>
>> is cumbersome to read/type repeatedly, e.g.
>>
>> DT[, long.variable.name := long.variable.name %>% function.a %>% function.b]
>
> In the case of long function chaining w/ magrittr, I almost always
> prefer breaking them up by line, so if I wanted to use it in
> data.table.[, it'd look something like this:
>
> DT[, long.variable.name := {
>    long.variable.name %>%
>    function.a %>%
>    function.b
> }]
>
> But again, we are in "personal taste" land -- I don't like having long
> lines stretch across my code ;-) ... anyway,  so not much one can
> objectively say here.
>
> We can talk about what it would take to implement %<>% in an objective
> sense, though -- first, not sure it's even possible w/o having to
> sniff for %<>% and rewrite the expression as `LHS := LHS %>% RHS ...`
> before evaluating? Is that right? Is that, perhaps, a thorny
> situation, and is it worth the effort?
>
> If I recall correctly, there's something magical about the `:=`
> operator that enabled it to modify the data.table by reference, but
> Matthew or Arun can come chime in here w/ more details ...
>
> -steve
>


More information about the datatable-help mailing list