Skip to content

Commit ab0d63d

Browse files
use smarter way to check if package is installed
1 parent 75b6123 commit ab0d63d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

R/utils.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,22 @@ is_installed <- function(path_pkg = ".") {
166166
pkg_name <- unname(read.dcf(path_desc)[, "Package"])
167167
list(
168168
name = pkg_name,
169-
installed = rlang::is_installed(pkg_name)
169+
installed = is_installed_impl(pkg_name)
170+
)
171+
}
172+
173+
# When a package is removed from the library with [remove.packages()] and then
174+
# loaded e.g. with [devtools::load_all()],
175+
# [rlang::is_installed()] and similar returns `TRUE`,
176+
# `pkg_name %in% installed.packages()` `FALSE` (but CRAN does not want to see
177+
# `installed.packages()` used since it may be slow).
178+
is_installed_impl <- function(pkg_name) {
179+
rlang::with_handlers(
180+
{
181+
find.package(pkg_name, lib.loc = .libPaths())
182+
TRUE
183+
},
184+
error = ~FALSE
170185
)
171186
}
172187

0 commit comments

Comments
 (0)