Skip to content

Commit

Permalink
check installed more robustly
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Nov 14, 2024
1 parent 25796d2 commit 4355f90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/crew_eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ crew_eval <- function(
if (anyNA(name)) {
name <- basename(tempfile(pattern = "unnamed_task_"))
}
if (installed_autometric) {
if (package_installed("autometric (>= 0.1.0)")) {
autometric::log_phase_set(phase = name)
on.exit(autometric::log_phase_reset())
}
Expand Down
7 changes: 2 additions & 5 deletions R/crew_worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ crew_worker <- function(
instance,
options_metrics = crew::crew_options_metrics()
) {
installed_autometric <- rlang::is_installed(
pkg = "autometric",
version = "0.1.0"
)
if (installed_autometric && !is.null(options_metrics$path)) {
autometric <- package_installed("autometric (>= 0.1.0)")
if (autometric && !is.null(options_metrics$path)) {
pids <- Sys.getpid()
names(pids) <- sprintf("crew_worker_%s_%s_%s", launcher, worker, instance)
autometric::log_start(
Expand Down
14 changes: 10 additions & 4 deletions R/utils_packages.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ load_packages <- function(packages, library) {
crew_assert(all(out), message = msg)
}

installed_autometric <- rlang::is_installed(
pkg = "autometric",
version = "0.1.0"
)
package_installed <- function(package) {
result <- .subset2(packages_installed, package)
if (is.null(result)) {
result <- rlang::is_installed(pkg = package)
packages_installed[[package]] <- result
}
result
}

packages_installed <- new.env(parent = emptyenv(), hash = TRUE)

0 comments on commit 4355f90

Please sign in to comment.