Skip to content

Commit

Permalink
Revert "number the saved objects"
Browse files Browse the repository at this point in the history
This reverts commit 0fc17ed.
  • Loading branch information
topepo committed Nov 14, 2024
1 parent 2e1ab63 commit d9cada0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
20 changes: 5 additions & 15 deletions R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 6 additions & 13 deletions tests/testthat/_snaps/bayes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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))
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d9cada0

Please sign in to comment.