-
Notifications
You must be signed in to change notification settings - Fork 49
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
docs: Use rlang::check_installed()
internally to install missing suggested packages on the fly
#2040
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Thank you for your help. Can you please split this PR into two? |
This comment was marked as resolved.
This comment was marked as resolved.
Locally: git checkout main
git pull
git checkout -b b-fix-ci
git cherry-pick suggests-follow This cherry-picks the last commit on top of the main branch, this is the one I'd like to merge first. Then, open a new pull request. After that: git checkout suggests-follow
git reset --hard HEAD^ This erases the last commit. For more complex splitting, interactive rebase is helpful. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
From my testing, I verified #1348. Indeed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following up! I think we might be able to get rid of the for
loops entirely.
There may be some code duplication, but this seems to work as intended now. getting rid of version, and message argument. I removed the I just added a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, cool!
b6f5382 adds a lot of noise here, can you please send this as a separate PR?
R/check_suggested.R
Outdated
installed <- map_lgl(packages, function(pkg) { | ||
is_installed(pkg) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installed <- map_lgl(packages, function(pkg) { | |
is_installed(pkg) | |
}) | |
installed <- map_lgl(packages, is_installed) |
Can this move even higher, outside if (!use)
? We could return immediately if all packages are installed, in all cases.
R/check_suggested.R
Outdated
installed <- map_lgl(packages, function(pkg) { | ||
is_installed(pkg) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installed <- map_lgl(packages, function(pkg) { | |
is_installed(pkg) | |
}) |
Redundant now?
R/check_suggested.R
Outdated
# Return early if all packages are installed. | ||
if (rlang::is_installed(packages)) { | ||
return(TRUE) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Return early if all packages are installed. | |
if (rlang::is_installed(packages)) { | |
return(TRUE) | |
} |
Not needed if we do an early return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried playing with the order without chaning test results, but it didn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly in a follow-up because this PR aims not to change the default behavior. (except gor removing the version and message argument from check_suggested
Reverted b6f5382 + added cli pluralization. Not sure about changing the order as it may result in different results, depending on which packages are installed on the system. |
4ced9c0
to
7fdd892
Compare
I force-pushed, if needed you can use git fetch
git reset --hard origin/suggests-follow to sync locally. Thanks for recognizing a real shortcoming in our approach to handling dependencies and for pushing through! |
rlang::check_installed()
internally to install missing suggested packages on the fly
Glad you like it and that you validated what I did. Always enriching. Tests still pass locally for me after changes you made. |
Looking into |
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 An example I shared earlier that could be what you were thinking about? But as I pointed out, the message shared by |
Thanks for the example, I missed that. The condition object |
This comment was marked as resolved.
This comment was marked as resolved.
41332d3
to
ecedfc8
Compare
…the loop in testing.
2f92bec
to
2b344ad
Compare
Thanks! |
Close #2039 . (possibly enough for #1735 and #1348 imo)
follow-up to #2036
Use only loop in testing.
Also, for
dm_gui()
, handle suggested at once will improve the UX significantly.I also return
TRUE
early if all packages are installed. Is that correct?