Making another package attach when my package is attached

I'm building a small package for local distribution among our analysts that encapsulates the connection code for our Oracle databases. I would like to make it so that attaching that package also makes available all of the functions from the package DBI.

In other words, I would like it so that instead of this


one could do this and have exactly the same effect


I tried looking at what happens when you do library(tidyverse) and it attaches ggplot2, tibble, etc., and I see there is a applying library to those packages, but if I just include library(DBI) in my package that doesn't do the trick. This seems like it should be something simple, but I don't know how to search for it.


1 Like

I may have found the right idea, doing @importFrom followed by @export, aka "re-exporting"?

E.g., as seen here in dplyr:

Would this be the preferred approach?

While re-exporting is "correct" in the sense that it will work I believe the easiest approach is including DBI in the Depends field of your DESCRIPTION file.


Ah-ha! "Depends" is the word I was looking for, thank you. Now that I know that, it becomes much easier to find it explained in places like here:
or here:

(Which it turns out I should be reading these anyway!)

Glad to be of service!

And as for the books I really recommend Hadley's R Packages. It was this book that got me started on the slippery slope of package development, all the way to CRAN submission.