Johan Larsson Johan Larsson - 1 year ago 87
R Question

Should I avoid programming packages with pipe operators?

Are there any objective reasons for why pipe operators from the R package

, such as
, should be avoided when I program packages in R?

More specifically, I want to know if using pipe operators might cause coding conflicts or (positively or negatively) affect performance. I am looking for specific, concrete examples of such cases.

Answer Source

Like all advanced functions written in R, %>% carries a lot of overhead, so don't use it in loops (this includes implicit loops, such as the *apply family, or the per group loops in packages like dplyr or data.table). Here's an example:

x = 1:10

system.time({for(i in 1:1e5) identity(x)})
#   user  system elapsed 
#   0.07    0.00    0.08 
system.time({for(i in 1:1e5) x %>% identity})
#   user  system elapsed 
#  15.39    0.00   16.68 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download