Skip to content

Commit

Permalink
change name of gp object and test saves
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Nov 14, 2024
1 parent d9cada0 commit fce7e6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
5 changes: 3 additions & 2 deletions R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,11 @@ save_gp_results <- function(x, pset, ctrl, i, iter, candidates, score_card) {

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),
gp_fit <- x
res <- try(save(gp_fit, pset, i, candidates, score_card, file = file_name),
silent = TRUE)
if (inherits(res, "try-error")) {
rlang::warn(paste("Could not save GP results:", as.character(res)))
cli::cli_warn("Could not save GP results at iteration {i}: {as.character(res))}")

Check warning on line 883 in R/tune_bayes.R

View check run for this annotation

Codecov / codecov/patch

R/tune_bayes.R#L883

Added line #L883 was not covered by tests
}
invisible(res)
}
Expand Down
19 changes: 13 additions & 6 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 `spline_msg()`:
! Error in if (df < 0) : missing value where TRUE/FALSE needed
Caused by error in `prep()`:
! `deg_free` must be a whole number, not a numeric `NA`.
x Fold2: preprocessor 1/1:
Error in `step_spline_b()`:
Caused by error in `spline_msg()`:
! Error in if (df < 0) : missing value where TRUE/FALSE needed
Caused by error in `prep()`:
! `deg_free` must be a whole number, not a numeric `NA`.
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 predictors were not found in `data`: 'z'.
! The following predictor was not found in `data`: "z".
x Fold2: preprocessor 1/1:
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'z'.
! The following predictor was not found in `data`: "z".
Condition
Warning:
All models failed. Run `show_notes(.Last.tune.result)` for more information.
Expand All @@ -445,6 +445,13 @@

# retain extra attributes and saved GP candidates

Code
setdiff(new_obj, current_objs)
Output
[1] "candidates" "gp_fit" "i" "score_card"

---

Code
res2 <- tune_bayes(wflow, resamples = folds, param_info = pset, initial = iter1,
iter = iter2, control = control_bayes(save_workflow = TRUE))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ 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 fce7e6b

Please sign in to comment.