First R package : How am I supposed to handle loading library functions?

I'm building my first R package. While developing the package, I'd have my ~30 functions open and loaded. Before loading them, I would load all required libraries:

library(dplyr)
library<package2>
...
library<package n>

In my DESCRIPTION file, I have all the packages under Imports:

Imports:
dplyr,
<package2>
...
<package n>

Great, but now when I load my own library and begin running the 1st function, I get :

Error in mydf[c(11:16), c(21:22)] %>% stack() %>% pull(values) %>% drop_outliers(.,  : 
  could not find function "%>%"

Am I really expected to change every instance of %>% to dplyr::%>% ? This occurs hundreds of times throughout my functions. What about the other functions used hundreds of times?

I could use the zzz.R file to load the libraries , but from cursory reading online it seems this is a no-no. What do I do?

Hi @cwright1 ,

The online version of R Packages (2e) by Hadley Wickham and Jennifer Bryan has two great chapters on how to deal with dependencies:

Key takeaways:

  • Adding a package to the Imports in the DESCRIPTION file only ensures that package is installed on the users computer but does not automatically make the package's functions available to you,

  • Namespacing all your external function calls is a very good idea,

  • Some operators, such as %>% can't be namespaced using ::, so it is recommended you import these using Roxygen2 calls (e.g. @importFrom dplyr %>%) updating your DESCRIPTION file to match,

  • You do not need to namespace calls to your own package's functions,

NB, the native pipe |> doesn't need namespacing so can be used in place of %>% in many cases.