Skip to content

Commit

Permalink
Use requireNamespace rather than installed.packages() to check for fu…
Browse files Browse the repository at this point in the history
…ture.apply
  • Loading branch information
ck37 committed Apr 9, 2024
1 parent b24e64a commit f63b068
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/test_consequences.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test_consequences_data_frame <- function(model_frame, outcome_name, outcome_type

# Initial diagnostic stat calculation can be slow with large datasets,
# and/or many models, so give the option for parallelization.
if (parallel && "future.apply" %in% rownames(utils::installed.packages())) {
if (parallel && requireNamespace("future.apply", quietly = TRUE)) {
lapply_fun = future.apply::future_lapply
} else {
lapply_fun = lapply
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-test_consequences.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ test_that("test_consequences() works", {
)

expect_no_error({
if ("future.apply" %in% rownames(utils::installed.packages())) {
# This test is only run if the future.apply package is installed.
if (requireNamespace("future.apply", quietly = TRUE)) {
future::plan("multisession", workers = 2)
test_consequences(formula = cancer ~ cancerpredmarker + marker,
data = df_binary, parallel = TRUE)
Expand Down

0 comments on commit f63b068

Please sign in to comment.