I'm writing a small package that builds some custom types of graphs using ggplot2. Naturally, my source files are going to be littered with ggplot2 functions. I'm somewhat new to package development, and my understanding is that it's generally better to disambiguate namespaces using ::
within package sources. But putting ggplot2::
in front of everything seems like a great recipe for cluttering my code - I'd like to make it as readable and clear as possible to make it easier for my colleagues to work on my code as well.
Is there a way to give my source files access to the ggplot2 namespace? Using library
within a package seems to be a big no-no. Putting ggplot2
under "Depends" in the package DESCRIPTION almost does it, but only attaches ggplot2 when I attach my package (thus causing problems if my package is loaded but not attached). Finding a way to automatically attach ggplot2 when my package is loaded would solve those problems, though intuition is telling me this is probably a bad practice somehow.
As mentioned here, you can do this in the roxygen
comments:
If you are using many functions from another package, use @import package to import them all and make available without using ::.
Preferably you would put this in the R/packagename-package.R
file, that has other standard roxygen tags, like so:
#' @docType package
#' @name packagename
#' @import ggplot2
NULL