[datatable-help] Integration with magrittr

Steve Lianoglou lianoglou.steve at gene.com
Wed Jul 1 18:47:00 CEST 2015


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

-- 
Steve Lianoglou
Computational Biologist
Genentech


More information about the datatable-help mailing list