1

Pipes and dplyr are useful for quick data exploration. Some argue that in a package, their use is not ideal.

In a package, I have to first add a package to the dependency. Like this devtools::use_package("dplyr")

And than I have to prefix it with dplyr:: when I use any function. How do I do that for the pipe operator? do I say: magrittr::%>%?

I would ideally use in a package a code like this:

data %<>% group_by(a,b,c) %>% summarize(total=sum(d)) %>% ungroup()

Do I have to always say

data magrittr::%<>% dplyr::group_by(a,b,c) magrittr::%>% dplyr::summarize(total=sum(d)) %>% ungroup()

What is the best practice for pipes and dplyr in an R package?

userJT
  • 11,486
  • 20
  • 77
  • 88

1 Answers1

7

Rather than repeated magrittr::%>% calls, I would suggest importing the pipe as part of your package. This way you can use the pipe within your own code, without the repeated ::.

In use this:

#' @importFrom magrittr %>%
magrittr::`%>%`
Jake Kaupp
  • 7,892
  • 2
  • 26
  • 36