roxygen2 icon indicating copy to clipboard operation
roxygen2 copied to clipboard

roxygen2::roxygenize throws error for generic setGeneric all.equal

Open BGWKlein opened this issue 6 months ago • 2 comments

I am trying to define an all.equal method for my object of the S4 class hydts in my package. When I try to create the documentation using devtools::document or roxygen2::roxygenize() in RStudio (Windows 10, roxygen2 version 7.3.2, RStudio 2024.04.0), I get the error at the end. I tried two versions to define all.equal, but both lead to this error. Probably something is wrong with my method definition.

first version

#' @export
all.equal.hydts <- function(target, current, ...) {TRUE}

#' @export
setMethod("all.equal", signature(target = "hydts", current =  "hydts"), all.equal.hydts)

second version without explicit definition for hydts

#' @exportMethod all.equal
if (!isGeneric("all.equal")) { setGeneric("all.equal", function(target, current, ...) standardGeneric("all.equal")) }

Error message:

Error in `map2()`:
i In index: 1.
i With name: all.equal.
Caused by error in `basename()`:
! Zeichenkettenvektor als Argument erwartet
Backtrace:
     x
  1. +-base::suppressPackageStartupMessages(...)
  2. | \-base::withCallingHandlers(expr, packageStartupMessage = function(c) tryInvokeRestart("muffleMessage"))
  3. +-devtools::document(roclets = c("rd", "collate", "namespace"))
  4. | \-roxygen2::roxygenise(pkg$path, roclets)
  5. |   \-base::lapply(...)
  6. |     +-roxygen2 (local) FUN(X[[i]], ...)
  7. |     \-roxygen2:::roclet_process.roclet_namespace(X[[i]], ...)
  8. |       \-roxygen2:::warn_missing_s3_exports(blocks, env)
  9. |         \-purrr::map2(...)
 10. |           \-purrr:::map2_("list", .x, .y, .f, ..., .progress = .progress)
 11. |             +-purrr:::with_indexed_errors(...)
 12. |             | \-base::withCallingHandlers(...)
 13. |             +-purrr:::call_with_cleanup(...)
 14. |             \-roxygen2 (local) .f(.x[[i]], .y[[i]], ...)
 15. |               \-roxygen2:::warn_roxy_function(fun, "S3 method {.arg {name}} needs @export or @exportS3method tag")
 16. |                 \-roxygen2:::warn_roxy(file, line, message, parent = parent, envir = envir)
 17. |                   +-cli::style_hyperlink(...)
 18. |                   +-base::paste0(basename(file), ":", line)
 19. |                   \-base::basename(file)
 20. \-base::.handleSimpleError(...)
 21.   \-purrr (local) h(simpleError(msg, call))
 22.     \-cli::cli_abort(...)
 23.       \-rlang::abort(...)
Ausfuehrung angehalten

Exited with status 1.

BGWKlein avatar Jul 01 '25 06:07 BGWKlein

This looks like a bug in warn_missing_s3_exports(), which happens, I think, because all.equal was an S3 method, but setMethod() has turned it into an S4 generic. This is clearly a roxygen2 bug, but unfortunately I can't see an obvious work around.

hadley avatar Oct 07 '25 22:10 hadley

Thanks for looking into it, I hope there will be a solution in the future, my current workaround is not very convinient :-):

  1. rename all all.equal occurences to all_equal
  2. run devtools::document
  3. rename all_equal occurences to all.equal
  4. build package

BGWKlein avatar Nov 03 '25 16:11 BGWKlein