My package uses ggplot2
extensively to make custom plots. I import ggplot2
in the NAMESPACE
file. I can build, install, and load the package into R without errors. But when I call a function from my package, it complains it can't find a function in that imported package. The function that I called had absolute nothing to do with plotting and didn't make use of anything from ggplot2
. How can I make function calls from my package work without these types of errors?
Error in theme_beata() (from plot.R#14) : could not find function "theme_classic"
The first function erroring is:
#' A custom ggplot2 theme for Beata
#' @import ggplot2
#' @family themes
#' inheritParams ggplot2::theme_classic
#' @export
theme_beata <- function(base_size = 14, base_family="serif", ticks = TRUE) {
ret <- theme_classic() +
theme(axis.line = element_line(size=0.6),
axis.text = element_text(size = base_size),
axis.title = element_text(size= base_size + 2),
title = element_text(size=base_size + 4))
if (!ticks) {
ret <- ret + theme(axis.ticks = element_blank())
}
ret
}
I am using devtools
and roxygen2
to document my package. I also discovered I am now getting this error when running document()
.
> document()
Updating pkg documentation
Loading pkg
Error in theme_beata() (from plot.R#11) : could not find function "theme_classic"
> traceback()
13: theme_beata()
12: as.vector(y)
11: setdiff(names(theme_gray()), names(new))
10: ggplot2::theme_set(theme_beata()) at plot.R#25
9: eval(expr, envir, enclos)
8: eval(exprs[i], envir)
7: source_one(file, envir = envir)
6: source_many(paths, env)
5: force(code)
4: in_dir(file.path(pkg$path, "R"), source_many(paths, env))
3: load_code(pkg)
2: load_all(pkg)
1: document()
From reading Hadley's book on packaging, I don't think the DESCRIPTION
matters in terms of exports, but below is the bottom part:
Depends: R (>= 3.1.0)
License: file LICENSE
LazyData: false
Imports:
dplyr (>= 0.4.0),
tidyr (>= 0.1.0),
XLConnect,
pryr,
stringr,
devEMF,
assertthat,
grid,
ggplot2,
ggthemes,
GGally,
broom,
scales
Suggests:
lattice
My NAMESPACE
has the following imports:
import(XLConnect)
import(dplyr)
import(ggplot2)
import(ggthemes)
import(stringr)
import(tidyr)