Skip to content
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

roxygenize error: "Caused by error in basename(): a character vector argument expected" #1589

Open
andrew-schulman opened this issue Feb 2, 2024 · 6 comments

Comments

@andrew-schulman
Copy link

andrew-schulman commented Feb 2, 2024

I've been successfully building my package documentation until now, up through roxygen2 7.2.3. But with version 7.3.0 and later, it fails:

> roxygen2::roxygenize(roclets = c('rd','collate','namespace','vignette'))
ℹ Loading DMRI
Error in `map2()`:In index: 1.With name: log.debug.
Caused by error in `basename()`:
! a character vector argument expected
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/purrr_error_indexed>
Error in `map2()`:In index: 1.With name: log.debug.
Caused by error in `basename()`:
! a character vector argument expected
---
Backtrace:1. └─roxygen2::roxygenize(...)
  2.   └─base::lapply(...)
  3.     ├─roxygen2 (local) FUN(X[[i]], ...)
  4.     └─roxygen2:::roclet_process.roclet_namespace(X[[i]], ...)
  5.       └─roxygen2:::warn_missing_s3_exports(blocks, env)
  6.         └─purrr::map2(...)
  7.           └─purrr:::map2_("list", .x, .y, .f, ..., .progress = .progress)
  8.             ├─purrr:::with_indexed_errors(...)
  9.             │ └─base::withCallingHandlers(...)
 10.             ├─purrr:::call_with_cleanup(...)
 11.             └─roxygen2 (local) .f(.x[[i]], .y[[i]], ...)
 12.               └─roxygen2:::warn_roxy_function(fun, "S3 method {.arg {name}} needs @export or @exportS3method tag")
 13.                 └─roxygen2:::warn_roxy(file, line, message, parent = parent, envir = envir)
 14.                   ├─cli::style_hyperlink(...)
 15.                   │ └─base::paste0(...)
 16.                   ├─base::paste0(basename(file), ":", line)
 17.                   └─base::basename(file)
Run rlang::last_trace(drop = FALSE) to see 4 hidden frames.

Apparently one of my S3 methods is missing an @export tag, but since the warning message fails, I can't tell which one. Running again with debug helps to show what the trouble is:

> debug(roxygen2:::warn_roxy_function) 
> roxygen2::roxygenize(roclets = c('rd','collate','namespace','vignette'))
Setting `RoxygenNote` to "7.3.1"Loading DMRI
debugging in: warn_roxy_function(fun, "S3 method {.arg {name}} needs @export or @exportS3method tag")
debug: {
    srcref <- attr(fun, "srcref")
    file <- attr(srcref, "srcfile")$filename
    line <- as.vector(srcref)[[1]]
    warn_roxy(file, line, message, parent = parent, envir = envir)
}
Browse[2]> attr(fun, "srcref")
NULL

So warn_roxy_function is trying to create a warning message based on attr(fun, "srcref"), but the attribute value is empty, which causes an error further down the line.

@PierreENOlivier
Copy link

Same issue here and I can't tell from the error which S3 method is missing a tag.

@venpopov
Copy link

I got the same issue, but no methods were missing tags. Restarting the R session made it go away...

@PierreENOlivier
Copy link

I got the same issue, but no methods were missing tags. Restarting the R session made it go away...

I restarted several times and it did not work. And then, did some work, restarted and it magically stopped throwing errors.
In the meantime, I tried to install the fortran compiler that seemed to be missing. Maybe that fixed it.

@GegznaV
Copy link

GegznaV commented Mar 7, 2024

The same issue is on GitHub Actions. How to solve it? Use the previous version of Roxygen2 where the issue was not present?

@andrew-schulman
Copy link
Author

Yes, you can work around it by reverting to roxygen2 version 7.2.3. Or, you can give up and add @export tags (that you probably don't want) to the functions that are missing them. You can tell which functions those are from the error message. The line that says With name: tells you the name of the function that triggered the error.

@venpopov
Copy link

venpopov commented Mar 7, 2024

I just figured out when this happens for me. If I have a breakpoint setup inside a method, and I run document(), the above error would appear. Removing the breakpoint removes the error. There may be multiple causes of the same error, but this is what was causing it for me.

Reproducible example:

#' @export
summary.myclass <- function(object) {
  cat("This is a summary of myclass\n")
}

running document() produces no errors. However, if I have a breakpoint setup within the Rstudio gui:

image

and I run document() I get this error:

Error in `map2()`:In index: 1.With name: summary.myclass.
Caused by error in `basename()`:
! a character vector argument expected
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
In class(f) <- c("s3method", "function") :
  Setting class(x) to multiple strings ("s3method", "function", ...); result will no longer be an S4 object  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants