tidyverse/dplyr in regular R application

dplyr
tidyverse

#21

Lots of food for thought here.

One comment that I believe has not been raised: if you absolutely, positively need the pipe (as I do) then it can and should be imported from magrittr. It comes with much less baggage than dplyr.


#22

Importing the pipe is not really an issue from the dependency aspect, as magrittr just depends on base and is very stable. Just be aware that pipes have significant overhead, and don't use it on loops/applies with lots of operations, or in simple functions that might be used inside of loops.

library(magrittr)
library(bench)
bench::mark(
  for (i in seq_len(1e5)){ mean(c(1, 2))},
  for (i in seq_len(1e5)){ c(1, 2) %>% mean()},
  iterations = 5
)

# expression                       median mem_alloc
# <chr>                          <bch:tm> <bch:byt>
# 1 for (i in seq_len(1e+05)) {... 310.07ms    12.3KB
# 2 for (i in seq_len(1e+05)) {...    7.27s    26.7MB

#23

note also that magrittr is not the only way to pipe :

library(microbenchmark)
library(magrittr)
library(wrapr)
library(pipeR)
`%.%` <- function(e1,e2)
  eval.parent(eval(substitute(substitute(e2,list(. = substitute(e1))))))

set.seed(99)
z = sample(10000,4,TRUE)

microbenchmark(
  magrittr = z %>% unique %>% list, 
  wrapr = z %.>% unique %.>% list, 
  pipeR = z %>>% unique %>>% list,
  simplistic_pipe = z %.% unique(.) %.% list(.),
  fake_pipe = {z -> .; unique(.) -> .; list(.)},
  list(unique(z)),
unit = "relative")
#> Unit: relative
#>             expr       min        lq      mean    median        uq
#>         magrittr 16.022222 17.915254 16.209680 17.988950 15.820084
#>            wrapr  8.911111 11.237288  9.257725  9.889503  8.974895
#>            pipeR  7.200000  8.093220  7.295321  7.558011  6.979079
#>  simplistic_pipe  3.555556  3.838983  6.233702  3.740331  3.497908
#>        fake_pipe  1.133333  1.177966  1.072513  1.204420  1.154812
#>  list(unique(z))  1.000000  1.000000  1.000000  1.000000  1.000000
#>         max neval cld
#>  18.3527013   100   c
#>   6.8246687   100  b 
#>   7.1488277   100  b 
#>  30.6248726   100 ab 
#>   0.7298675   100 a  
#>   1.0000000   100 a

#24

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.