-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@exportS3Method fails when package not imported or already in global namespace #1085
Comments
Can you please provide a reprex following the advice in https://github.com/r-lib/roxygen2/blob/master/.github/SUPPORT.md#making-a-reprex? |
Thanks @hadley. I couldn't make this work using There is only a single R file which has the contents:
There are three workarounds. Firstly, if the second (optional) parameter is provided to It may be that the best option for now is to direct package authors to use the two parameter form of |
(Note to self: when fixing this, also make sure to update namespace vignette with use of |
Export alone does not export S3method for non-loaded packages (in R-4) See r-lib/roxygen2#1085
Minimal reprex: library(roxygen2)
roc_proc_text(namespace_roclet(), "
#' @exportS3Method knitr::knit_print
knit_print.s3example <- function(x, ...) {
}
")
#> Warning: [<text>:2] @exportS3Method `@exportS3Method` and `@exportS3Method
#> generic` must be used with an S3 method
#> character(0) Created on 2022-04-06 by the reprex package (v2.0.1) Need to use the generic in the tag to find the class name from the generic. |
With the move to R 4.0.0, I've come across an issue with one of my packages where I wanted to include S3 methods without introducing a dependency on the package that defines the generic. I'd previously done this by
@export
ing the function without an@importFrom
, which meant that anexport
rather thanS3method
directive was written to NAMESPACE. However, now that R 4.0.0 doesn't look in the global namespace for S3 methods, this no longer worked.As per duckmayr's answer to my StackOverflow question, the answer comes from using
@exportS3Method package::generic_function
without an@importFrom
. However, this fails unless the relevant package has already been loaded into the global namespace before a call toroxygen2::roxygenise
. Within RStudio, this means that the Document option in the Build pane fails. Is there any chance of modifying the check that leads to the error@exportS3Method
and@exportS3Method generic
must be used with an S3 method' and therefore fails to include the relevant lines in NAMESPACE?The text was updated successfully, but these errors were encountered: