Skip to content

Undocumented S3 Method Check Fails when srcrefs are Missing #1710

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

Open
smilberg opened this issue Apr 20, 2025 · 0 comments · May be fixed by #1711
Open

Undocumented S3 Method Check Fails when srcrefs are Missing #1710

smilberg opened this issue Apr 20, 2025 · 0 comments · May be fixed by #1711

Comments

@smilberg
Copy link

smilberg commented Apr 20, 2025

Running roxygenize on a package with undocumented S3 methods and without srcrefs fails as follows:

Error in map2(undocumented, names(undocumented), function(fun, name) { : 
  ℹ In index: 1.
ℹ With name: c.blah.
Caused by error in `basename()`:
! a character vector argument expected

The error relates to the addition of checks for undocumented S3 methods from #1534 which implicitly assumes srcrefs are always present. Downstream code then fails because it gets NULL instead of a string.

Recreating the error is a bit tricky b/c we need a package without srcrefs, but here is a reasonably small example that reproduces the error:

pkg.name <- 'pkguqhr'
DESCRIPTION <- sprintf('
Package: %s
Version: 0.0
Encoding: UTF-8
Roxygen: list(load="installed")', pkg.name)
NAMESPACE <- ''
RCODE <- 'c.blah <- function(...) NULL'
if(!pkg.name %in% rownames(installed.packages())) {
  pkg.dir <- tempfile(pkg.name)
  dir.create(file.path(pkg.dir, "R"), recursive=TRUE)
  writeLines(DESCRIPTION, file.path(pkg.dir, 'DESCRIPTION'))
  writeLines(NAMESPACE, file.path(pkg.dir, 'NAMESPACE'))
  writeLines(RCODE, file.path(pkg.dir, 'R', 'pkg.R'))

  install.packages(pkg.dir, type='src', repos=NULL, quiet=TRUE)
  try(roxygen2::roxygenise(pkg.dir))
  remove.packages(pkg.name)
} else {
  stop(
    "Please either remove ", pkg.name, 
    " or find another name for this test package"
  )
}

Notice the Roxygen: list(load="installed"). Assuming the above is in test.R then:

R --vanilla -q -f test.R

Reproduces the error.

Relates to #1589. #1711 provides a simple fix, but probably better would be to have an accessor function for srcrefs that is guaranteed to return in standard format, and then use that function everywhere, but that's a bigger change.

smilberg pushed a commit to smilberg/roxygen2 that referenced this issue Apr 20, 2025
smilberg pushed a commit to smilberg/roxygen2 that referenced this issue Apr 20, 2025
@smilberg smilberg linked a pull request Apr 20, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant