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

Speed up check_installed() - shortcut when package is already loaded #1780

Merged
merged 4 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions R/session.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ check_installed <- function(pkg,
action = NULL,
call = caller_env()) {
check_dots_empty0(...)

# Fast path. Note that if `version` is supplied, this always falls through to the
# more expensive check.
if (is.null(version)) {
loaded <- lapply(pkg, function(x) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment about what happens when a version is supplied?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in c65352f.

is.character(x) && nzchar(x) && is.environment(.getNamespace(x))
})
if (all(as.logical(loaded))) {
return(invisible(NULL))
}
}

check_action(action)

info <- pkg_version_info(pkg, version = version, compare = compare)
Expand Down
Loading