Skip to content

Commit

Permalink
Paste the outputs of deparse() to guarantee a length-1 vector (Fixes #…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mikemahoney218 authored Nov 3, 2023
1 parent be593b9 commit f476210
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
9 changes: 8 additions & 1 deletion R/nest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-nesting.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit f476210

Please sign in to comment.