From 95d9f88847dd598ee3c3524ca3ba7f0dba2f0cab Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Fri, 20 Oct 2023 11:32:32 -0700 Subject: [PATCH] Add future_globals test --- tests/testthat/test-cross-validation.R | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/testthat/test-cross-validation.R b/tests/testthat/test-cross-validation.R index 29aeda4c7..a321bddff 100644 --- a/tests/testthat/test-cross-validation.R +++ b/tests/testthat/test-cross-validation.R @@ -47,6 +47,24 @@ test_that("Basic cross validation works", { expect_equal(class(x$models[[1]]), "sdmTMB") }) +test_that("Cross validation in parallel with globals", { + # https://github.com/pbs-assess/sdmTMB/issues/127 + skip_on_ci() + skip_on_cran() + d <- pcod + spde <- make_mesh(d, c("X", "Y"), cutoff = 15) + set.seed(2) + future::plan(future::multisession, workers = 2L) + fam <- tweedie(link = "log") + x <- sdmTMB_cv( + density ~ 0 + depth_scaled + depth_scaled2 + as.factor(year), + data = d, mesh = spde, + family = fam, time = "year", k_folds = 2L, future_globals = 'fam' + ) + expect_s3_class(x$models[[1]], "sdmTMB") + future::plan(future::sequential) +}) + test_that("Leave future out cross validation works", { skip_on_ci() skip_on_cran()