Skip to content

Conversation

@shikokuchuo
Copy link
Member

Can safely shortcut when package versions are not specified.

This prevents the full code path being run every time the function is called within a session, and is equivalent to the user memoizing the result.

Takes 3 microseconds, which is not much to give back on the initial run when we've saved some hundreds of microseconds in #1777.

library(rlang)
bench::mark(check_installed("later"))
#> # A tibble: 1 × 6
#>   expression                        min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                   <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 "check_installed(\"later\")"   2.47µs   3.01µs   305568.    5.61MB     30.6

Created on 2025-02-20 with reprex v2.1.1

This should be applied with #1777 but is independent of that.
Closes #1776.

check_dots_empty0(...)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Propose a faster version of check_installed()

2 participants