diff --git a/R/tune_bayes.R b/R/tune_bayes.R index efce6757..d55af93a 100644 --- a/R/tune_bayes.R +++ b/R/tune_bayes.R @@ -874,22 +874,12 @@ save_gp_results <- function(x, pset, ctrl, i, iter, candidates, score_card) { return(invisible(NULL)) } - # numerate the objects that change from iters - chr_iter <- recipes::names0(iter, "")[i] - gp_name <- glue::glue("gp_fit_{chr_iter}") - assign(gp_name, x) - can_name <- glue::glue("candidates_{chr_iter}") - assign(can_name, candidates) - score_name <- glue::glue("score_card_{chr_iter}") - assign(score_name, score_card) - - file_name <- glue::glue("{tempdir()}/gp_candidates_{chr_iter}.RData") - - saves <- c("i", "iter", "pset", gp_name, can_name, score_name) - - res <- try(save(list = saves, file = file_name), silent = TRUE) + nm <- recipes::names0(iter, "gp_candidates_")[i] + file_name <- glue::glue("{tempdir()}/{nm}.RData") + res <- try(save(x, pset, i, candidates, score_card, file = file_name), + silent = TRUE) if (inherits(res, "try-error")) { - cli::cli_warn("Could not save GP results at iteration {i}: {as.character(res))}") + rlang::warn(paste("Could not save GP results:", as.character(res))) } invisible(res) } diff --git a/tests/testthat/_snaps/bayes.md b/tests/testthat/_snaps/bayes.md index 80a29641..d2e2f99f 100644 --- a/tests/testthat/_snaps/bayes.md +++ b/tests/testthat/_snaps/bayes.md @@ -393,12 +393,12 @@ Message x Fold1: preprocessor 1/1: Error in `step_spline_b()`: - Caused by error in `prep()`: - ! `deg_free` must be a whole number, not a numeric `NA`. + Caused by error in `spline_msg()`: + ! Error in if (df < 0) : missing value where TRUE/FALSE needed x Fold2: preprocessor 1/1: Error in `step_spline_b()`: - Caused by error in `prep()`: - ! `deg_free` must be a whole number, not a numeric `NA`. + Caused by error in `spline_msg()`: + ! Error in if (df < 0) : missing value where TRUE/FALSE needed Condition Warning: All models failed. Run `show_notes(.Last.tune.result)` for more information. @@ -415,10 +415,10 @@ Message x Fold1: preprocessor 1/1: Error in `get_all_predictors()`: - ! The following predictor was not found in `data`: "z". + ! The following predictors were not found in `data`: 'z'. x Fold2: preprocessor 1/1: Error in `get_all_predictors()`: - ! The following predictor was not found in `data`: "z". + ! The following predictors were not found in `data`: 'z'. Condition Warning: All models failed. Run `show_notes(.Last.tune.result)` for more information. @@ -445,13 +445,6 @@ # retain extra attributes and saved GP candidates - Code - setdiff(new_obj, current_objs) - Output - [1] "candidates_1" "gp_fit_1" "i" "iter" "score_card_1" - ---- - Code res2 <- tune_bayes(wflow, resamples = folds, param_info = pset, initial = iter1, iter = iter2, control = control_bayes(save_workflow = TRUE)) diff --git a/tests/testthat/test-bayes.R b/tests/testthat/test-bayes.R index c3162568..59bd5ff3 100644 --- a/tests/testthat/test-bayes.R +++ b/tests/testthat/test-bayes.R @@ -481,10 +481,7 @@ test_that("retain extra attributes and saved GP candidates", { files <- list.files(path = tempdir(), pattern = "^gp_candidates") expect_true(length(files) == iter2) - current_objs <- c(ls(), "current_objs") - load(file.path(tempdir(), "gp_candidates_1.RData")) - new_obj <- ls() - expect_snapshot(setdiff(new_obj, current_objs)) + expect_snapshot( res2 <- tune_bayes(