From f476210f4a3313caae63eff7f9dd3d1fa74424da Mon Sep 17 00:00:00 2001 From: Michael Mahoney Date: Fri, 3 Nov 2023 06:19:49 -0400 Subject: [PATCH] Paste the outputs of deparse() to guarantee a length-1 vector (Fixes #459) (#461) * Paste the outputs of deparse() to guarantee a length-1 vector (#459) deparse1() was added in 4.0.0, so copied the internals for back-compatibility. * Style test --- NEWS.md | 2 ++ R/nest.R | 9 ++++++++- tests/testthat/test-nesting.R | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 2f7c6d02..39587232 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # rsample (development version) +* `nested_cv()` no longer errors if `outside` is a long call (#459, #461). + # rsample 1.2.0 * The new `initial_validation_split()`, along with variants `initial_validation_time_split()` and `group_initial_validation_split()`, generates a three-way split of the data into training, validation, and test sets. With the new `validation_set()`, this can be turned into an `rset` object for tuning (#403, #446). diff --git a/R/nest.R b/R/nest.R index e34e5522..d3c6b080 100644 --- a/R/nest.R +++ b/R/nest.R @@ -60,7 +60,14 @@ nested_cv <- function(data, outside, inside) { outer_cl <- cl[["outside"]] if (is_call(outer_cl)) { - if (grepl("^bootstraps", deparse(outer_cl))) { + using_bootstraps <- grepl( + "^bootstraps", + paste( + deparse(outer_cl, width.cutoff = 500L), + collapse = " " + ) + ) + if (using_bootstraps) { warn(boot_msg) } outer_cl <- rlang::call_modify(outer_cl, data = data) diff --git a/tests/testthat/test-nesting.R b/tests/testthat/test-nesting.R index bef11e9d..efa294c4 100644 --- a/tests/testthat/test-nesting.R +++ b/tests/testthat/test-nesting.R @@ -92,6 +92,21 @@ test_that("rsplit labels", { expect_equal(all_labs, original_id) }) +test_that("long calls don't error", { + skip_if_not_installed("modeldata") + expect_no_error( + nested_cv( + modeldata::Chicago, + outside = sliding_period( + index = date, + period = "month", + origin = modeldata::Chicago$date[1] + ), + inside = vfold_cv(v = 4) + ) + ) +}) + # ------------------------------------------------------------------------------ # `[` skip_if_not_installed("withr")