Expand @import directives to explicit importFrom() - #1898
Conversation
|
What if we introduced a new tag for this? Like |
|
That would be reasonable, especially as a first step to gain practical experience with the approach, but it would not feel like we're creating a pit of success for our users to fall into :) |
|
Right, I think we'd still want to change long term, but I worry that it's too big of a change to push through now (even in a minor release). If we used a new tag, I'm happy to merge this and encourage people to use it. (It would also be an interesting place to try and claude code automated patching system) |
40c0cc5 to
3aa4100
Compare
|
@hadley I moved the expansion to a new Unlike I went for an exclusion syntax that is consistent with the existing #' @importAllFrom dplyr -filter -lag
#' @importAllFrom rlang -":="We need the imported package to be installed to figure out the exports. Other features in roxygen2 like |
| # Splits an `@importAllFrom` value into the package to expand and the symbols to | ||
| # leave out. An exclusion is a word with a `-` prefix, e.g. `-abort`. Exclusions | ||
| # may be quoted: `-"-.Date"`, ``-`-.Date` ``, or `-'-.Date'`. | ||
| parse_import_all_from <- function(vals) { |
There was a problem hiding this comment.
Would it be better to use select_args_text?
There was a problem hiding this comment.
See last commit:
- Now parses tags with
tag_two_part() - Then parses arguments with
select_args_text() - New
classargument threaded throughroxy_warnand used to handle failures
| #' #' @importAllFrom rlang | ||
| #' | ||
| #' # This results in the following lines: | ||
| #' # importFrom(rlang, |
There was a problem hiding this comment.
It occurs to me that the downside of this approach is that now if rlang removes a symbol, this package will fail to load. With @import (as long as you didn't actually use the symbol) that isn't a problem.
There was a problem hiding this comment.
oooh that's a very good point. This pretty much kills the approach.
The alternative is that once Oak symbol resolution is robust enough, we wrap it in an R package and then use that the way you'd use {globals} to figure out from usage the minimum set of symbols to import.
Branched from #1892
This PR expands
@import pkgdirectives to explicit imports in animportFrom(pkg, sym1, sym2, ...)expression. This pins the set of imported symbols between rounds ofdocument(), and prevents users from getting issues at load time when a package update creates a conflict. Instead, new conflicts are deferred until the next time the maintainer documents, where the conflict causes an error that forces the maintainer to resolve it with anexcept =clause.Ideally we'd detect symbols actually used by the package with a mechanism like
findGlobals(). Until we can do it reliably, possibly with the help of Oak and annotations, I've opted to just import every exports.