In a package, I have a function foo
that returns an object of class "foo"
. I also have a plot
method for class "foo"
.
#' Create a "foo" object
#'
#' @param x An \R object.
#'
#' @return
#' A "foo" object.
#'
#' @examples
#' foo_object <- foo(1)
#' plot.foo(foo_object)
#'
#' @export
foo <- function(x) {
structure(x, class = "foo")
}
#' @export
#' @importFrom graphics plot
plot.foo <- function(x, ...) {
class(x) <- setdiff(class(x), "foo")
plot(x)
invisible(NULL)
}
I can evaluate the example code without issue after I load the package with devtools::load_all
. However, devtools::check
complains:
Error in plot.foo(foo_out) : could not find function "plot.foo"
Execution halted
It seems that my R session knows about plot.foo
, but not devtools::check
. What is going on?
Edit: To clarify, devtools::check
passes when I replace the call plot.foo(foo_object)
under @examples
with plot(foo_object)
. That doesn't surprise me, and users should call the generic anyway. My question remains: why is devtools::check
unable to find plot.foo
, given that I have used the @export
tag and S3method(plot, foo)
appears in NAMESPACE
after devtools::document
?