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 fails with missing NAMESPACE when using setMethod #1693

Open
hdarjus opened this issue Jan 10, 2025 · 0 comments
Open

roxygenize fails with missing NAMESPACE when using setMethod #1693

hdarjus opened this issue Jan 10, 2025 · 0 comments

Comments

@hdarjus
Copy link

hdarjus commented Jan 10, 2025

I would like to re-open #1144 here, because #1538 seems to be inadequate for the case in the title.

I have created an MWE under https://github.com/hdarjus/badInstall. roxygen2::roxygenize() fails for the package as is (Case 1). However, after renaming NAMESPACE2 to NAMESPACE (Case 2), roxygen2::roxygenize() works even though the imports are technically the same: there are no imports in either cases.

I believe the issue is !file.exists(NAMESPACE) in

if (!made_by_roxygen(NAMESPACE) || !file.exists(NAMESPACE)) {

I think something similar to the following modified function could work:

update_namespace_imports <- function(base_path) {
  NAMESPACE <- file.path(base_path, "NAMESPACE")
  if (!made_by_roxygen(NAMESPACE)) {
    return(invisible())
  }

  local_namespace_exports <- if(!file.exists(NAMESPACE)) {
    character(0)
  } else {
     namespace_exports(NAMESPACE)
  }

  lines <- c(namespace_imports(base_path), local_namespace_exports)
  results <- c(made_by("#"), sort_c(unique(trimws(lines))))
  write_if_different(NAMESPACE, results, check = TRUE)  # maybe check again whether NAMESPACE exists

  invisible()
}

I did not have the time to test it, unfortunately.

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

1 participant