0

I use dplyr a lot in various functions which I am putting together into a package. I am not supposed to use library(dplyr) ever so I am trying to double colon everything. However I cannot seem to get the dplyr version right. When I do this for example:

SurveillanceLastToNow <- function(x, A_thing, Date) {
    x %>% dplyr::arrange_(A_thing, Date) %>% 
    dplyr::group_by_(A_thing) %>% dplyr::mutate(diffDate = difftime(Sys.Date(), 
         last(Date), units = "days"))
}

I get the error:

could not find function "%>%"

So my questions are

  1. Do I need to magrittr::%>% all the way through?....surely not
  2. Given how much I use dplyr, including most of its functions, how do I just load the whole thing on installing the package rather than :: everywhere

Basically I'm looking for the laziest way to use all the dplyr functions in my package

Frank
  • 66,179
  • 8
  • 96
  • 180
Sebastian Zeki
  • 6,690
  • 11
  • 60
  • 125
  • You could just import the functions (`dplyr::mutate`, `magrittr::%>%`, etc) into your package and then use them normally with no `package::` in the code. – John Paul Aug 31 '17 at 18:31

1 Answers1

0

You can simply put dplyr into the "depends" field of description file of your package, or if you don't want attach the package into the search path, you can put it into "imports" of description, but add a line import(dplyr) in the namespace file.

platypus
  • 516
  • 3
  • 8
  • Maybe I'm being dumb but when I run document("MyPackage") the import disappears from the NAMESPACE. Where does it go and do I have to re-add everytime I re-run the document function? – Sebastian Zeki Aug 31 '17 at 18:57
  • 1
    so if you are using roxygen, then you do need to add a line `#' @import dplyr` in one of your R files – platypus Aug 31 '17 at 20:41