From 2b25a04eb07f6412ead48ffed822719cc435e5fe Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Tue, 6 Dec 2022 15:54:19 -0800 Subject: [PATCH] put back global code --- R/tune_cluster.R | 9 +++++++++ tests/testthat/_snaps/tune_cluster.md | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/tune_cluster.R b/R/tune_cluster.R index b0bfff3b..673b2f20 100644 --- a/R/tune_cluster.R +++ b/R/tune_cluster.R @@ -326,6 +326,15 @@ tune_cluster_loop_iter <- function(split, load_pkgs(workflow) load_namespace(control$pkgs) + # After package loading to avoid potential package RNG manipulation + if (!is.null(seed)) { + # `assign()`-ing the random seed alters the `kind` type to L'Ecuyer-CMRG, + # so we have to ensure it is restored on exit + old_kind <- RNGkind()[[1]] + assign(".Random.seed", seed, envir = globalenv()) + on.exit(RNGkind(kind = old_kind), add = TRUE) + } + control_parsnip <- parsnip::control_parsnip(verbosity = 0, catch = TRUE) control_workflow <- workflows::control_workflow(control_parsnip) diff --git a/tests/testthat/_snaps/tune_cluster.md b/tests/testthat/_snaps/tune_cluster.md index 8bc9050a..4b3eb33b 100644 --- a/tests/testthat/_snaps/tune_cluster.md +++ b/tests/testthat/_snaps/tune_cluster.md @@ -118,8 +118,8 @@ # A tibble: 2 x 4 splits id .metrics .notes - 1 Fold1 - 2 Fold2 + 1 Fold1 + 2 Fold2 # select_best() and show_best() works