-
Notifications
You must be signed in to change notification settings - Fork 233
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
devtools::document() errors before NAMESPACE can be updated #1144
Comments
If it's helpful, I threw up this repository: https://github.com/daynefiler/badInstall. |
@jimhester any insight here? |
This is a roxygen2 issue so I've moved it there. |
A workaround is to delete the NAMESPACE file. It will be rebuilt without an error. |
Yeah, we don't have a good automated solution for this — as @adolgert suggests, your best bet is just to delete the |
It looks like this might be a regression introduced by 97c6c2d — we really need to do the namespace ore-processing before any code is run, but now we need to load the package in order to evaluate inline code. |
Related issue (please LMK if this is more appropriate as an independent issue), continued from r-lib/pkgload#239. I would expect |
Yeah, the problem is that roxygen2 is a mostly dynamic doc system, so it executes the code as a part of the tag generation. That means you need imports defined, which gets us into this circular dependency problem. It's possible to break the cycle in the same way as we did for collate (see |
Maybe there could be a new roclet |
Yeah, the problem is that it can't be a roclet, because all the roclet machinery assumes that you have not just the sources, but the package namespace. |
FWIW, I wrote a janky script to initialize the NAMESPACE before r_files <- list.files(
file.path(package_dir, "R"),
# exclude e.g. sysdata.rda
pattern = "\\.[rR]$",
full.names = TRUE
)
namespace_imports <- unlist(lapply(r_files, function(r_file) {
# NB: roxygen2::parse_package() will attempt to compile src code
file_roxy <- roxygen2:::tokenize_file(r_file)
unlist(lapply(file_roxy, function(roxy) {
unlist(lapply(roxy$tag, function(entry) {
# For entries '@import pkg', NAMESPACE entry is import(pkg)
# For entries '@importFrom pkg ...', it's importFrom(pkg, ...)
# ditto for @importClassesFrom and @importMethodsFrom.
switch(entry$tag,
import = ,
importFrom = ,
importClassesFrom = ,
importMethodsFrom = sprintf(
"%s(%s)",
entry$tag, toString(roxygen2:::auto_quote(entry$val))
)
)
}))
}))
}))
if (!is.null(namespace_imports)) {
# must fake the roxygen2 header in order for the next pass to
# process @exports correctly.
# NB: unique() doesn't necessarily eliminate all duplicate exports here.
writeLines(
c(roxygen2:::made_by("#"), "", sort(unique(namespace_imports))),
file.path(package_dir, "NAMESPACE")
)
} |
Also FWIW, I think the current documentation is a bit ?misleading?
That describes exactly what we wanted out of this roclet. But now it seems it's not possible to fully rely on that behavior because |
Oh hmmm, maybe I forgot that I already implemented this, and then broke it with another change? |
For us it is the pkgload update that breaks our flow, rather than anything in roxygen2 per se. We also found it's necessary in some cases working with S4 methods (haven't nailed down an MRE on what exactly triggers it). |
Ok yeah, the problem is that the package is being loaded before the Fixing this is going to require some work. I think we could either try to put off the markdown parsing until after |
FWIW the current code works in the vast majority of cases to initialize the NAMESPACE from scratch. Of ~500 packages we only see 4 packages and two classifications of error:
We patched the above snippet as an exported function and that fixed the S4 methods case, leaving only 1 package where the sysdata.Rda bug persists ( So, not sure it's worth fixing TBH, as long as workarounds are documented, and perhaps we could export the |
@MichaelChirico it bugs me enough that I'd prefer to fix it properly 😄 |
This comment was marked as outdated.
This comment was marked as outdated.
This effectively makes the preprocess method irrelevant, but there's no much point in removing it since there are so few extension authors. Fixes #1144
When running
devtools::document()
using roxygen2 to manage the namespace, the function errors before the NAMESPACE file can be updated/written.I have run into this in two situations:
(1) adding a new import; e.g. trying to add the
S4Vectors::setValidity2
function using#' @importFrom S4Vectors setvalidity2
:(2) renaming a generic method:
I am using RStudio: v1.3.959
The text was updated successfully, but these errors were encountered: