-
Notifications
You must be signed in to change notification settings - Fork 48
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
chore: Improve handling of suggested packages, add link in doc #2036
Conversation
Nice! I wonder if we should avoid the loop and go straight to vectors. AFAICT |
On a related note, |
In tests, I believe that it would only error. You would need
Edit: Ok, I see, but this would have to be a FR in rlang. I think that it could entirely be replaced by check_installed() when the use is required |
I'd rather remove all |
See the battery of the "Without xxx" tests here. We're removing suggested packages, one by one, and check that the tests still pass. |
Maybe something like that could be useful. But I don't know much about chaining. f <- function(pkg) {
rlang::local_interactive(FALSE)
rlang::try_fetch(
rlang::check_installed("rsvg2"),
error = function(e) {rlang::inform("The function is enhanced by the following package, ",parent = e, call = rlang::caller_fn())})
invisible()
}
f()
The function is enhanced by the following package,
Caused by error in `f()`:
! The package "rsvg2" is required. |
I don't follow. Would you like to look into removing the loop from the checking routine? I'm even proposing to have |
I could look into it. I may have time next week. the idea would just be to add an optional parameter check_installed("DiagrammeR")
#> The package is required.
check_installed("DiagrammeR", optional = TRUE)
#> The package "DiagrammeR" can be used to enhance the function. But I browsed a little through the use, and most usages in dm seem to be replaceable by check_suggest <- function(pkg, call = rlang::caller_env()) {
rlang::local_interactive(FALSE) # To avoid the prompt
rlang::try_fetch(
rlang::check_installed(pkg, reason = "to have an enhanced functionality.", call = call),
error = function(e) {rlang::inform("The function is enhanced by the following package, ", parent = e, call = call)})
invisible()
}
g <- function(x) {
check_suggest(c("ggplot2 (>= 3.5.0)", "rsvg", "sss"))
x**2
}
g(2)
#> The function is enhanced by the following package,
#> Caused by error in `g()`:
#> ! The packages "ggplot2" (>= 3.5.0) and "sss" are required to have an
#> enhanced functionality.
#> [1] 4 Created on 2023-10-12 with reprex v2.0.2 The only thing that would need to be changed here is to change required to optional. |
Thanks!
|
This comment has been minimized.
This comment has been minimized.
Current Aviator status
This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
Addresses #1735, closes #2035.
Briefly, it uses
check_installed()
in the check_suggested function to make it easier to install DiagrammeR. I guesscheck_suggests()
could be simplified further. (and get the function by chaining rather than naming.Mind the small tweak in tests to avoid skipping the test. We have to make it believe that we are not testing to avoid skipping the test. and actually record the message.
Note that
check_installed()
errors in non-interactive sessions.In an unrelated way, I added a link to the data frame vignette in the dm_nyc13 flights as I had issues to get started and this vignette helped me.