From e1f658dde498eab7dae22a096a0a4c31e1b9b752 Mon Sep 17 00:00:00 2001 From: seb09 Date: Thu, 15 Aug 2024 10:42:52 -0700 Subject: [PATCH 1/2] Updated example for nested_cv() Replaced as.data.frame() by the rsample accessor functions and changed the car name - Fixes #479 --- R/nest.R | 18 +++++++++--------- man/nested_cv.Rd | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/R/nest.R b/R/nest.R index d3c6b080..d2d3427e 100644 --- a/R/nest.R +++ b/R/nest.R @@ -34,18 +34,18 @@ #' inside = vfold_cv(v = 3) #' ) #' -#' first_outer_split <- bad_idea$splits[[1]] -#' outer_analysis <- as.data.frame(first_outer_split) -#' sum(grepl("Volvo 142E", rownames(outer_analysis))) +#' first_outer_split <- get_rsplit(bad_idea, 1) +#' outer_analysis <- analysis(first_outer_split) +#' sum(grepl("Camaro Z28", rownames(outer_analysis))) #' #' ## For the 3-fold CV used inside of each bootstrap, how are the replicated -#' ## `Volvo 142E` data partitioned? -#' first_inner_split <- bad_idea$inner_resamples[[1]]$splits[[1]] -#' inner_analysis <- as.data.frame(first_inner_split) -#' inner_assess <- as.data.frame(first_inner_split, data = "assessment") +#' ## `Camaro Z28` data partitioned? +#' first_inner_split <- get_rsplit(bad_idea$inner_resamples[[1]], 1) +#' inner_analysis <- analysis(first_inner_split) +#' inner_assess <- assessment(first_inner_split) #' -#' sum(grepl("Volvo 142E", rownames(inner_analysis))) -#' sum(grepl("Volvo 142E", rownames(inner_assess))) +#' sum(grepl("Camaro Z28", rownames(inner_analysis))) +#' sum(grepl("Camaro Z28", rownames(inner_assess))) #' @export nested_cv <- function(data, outside, inside) { cl <- match.call() diff --git a/man/nested_cv.Rd b/man/nested_cv.Rd index 826a9c47..cdb19761 100644 --- a/man/nested_cv.Rd +++ b/man/nested_cv.Rd @@ -48,16 +48,16 @@ bad_idea <- nested_cv(mtcars, inside = vfold_cv(v = 3) ) -first_outer_split <- bad_idea$splits[[1]] -outer_analysis <- as.data.frame(first_outer_split) -sum(grepl("Volvo 142E", rownames(outer_analysis))) +first_outer_split <- get_rsplit(bad_idea, 1) +outer_analysis <- analysis(first_outer_split) +sum(grepl("Camaro Z28", rownames(outer_analysis))) ## For the 3-fold CV used inside of each bootstrap, how are the replicated -## `Volvo 142E` data partitioned? -first_inner_split <- bad_idea$inner_resamples[[1]]$splits[[1]] -inner_analysis <- as.data.frame(first_inner_split) -inner_assess <- as.data.frame(first_inner_split, data = "assessment") +## `Camaro Z28` data partitioned? +first_inner_split <- get_rsplit(bad_idea$inner_resamples[[1]], 1) +inner_analysis <- analysis(first_inner_split) +inner_assess <- assessment(first_inner_split) -sum(grepl("Volvo 142E", rownames(inner_analysis))) -sum(grepl("Volvo 142E", rownames(inner_assess))) +sum(grepl("Camaro Z28", rownames(inner_analysis))) +sum(grepl("Camaro Z28", rownames(inner_assess))) } From a80cd6f9c232f7f66ff2bfcc31b1598d6c6ad744 Mon Sep 17 00:00:00 2001 From: Hannah Frick Date: Thu, 15 Aug 2024 11:48:42 -0700 Subject: [PATCH 2/2] add Seb to NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 2e678b33..0a0e5147 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ * Started moving error messages to cli (#499, #502). +* Fixed example for `nested_cv()` (@seb09, #520). + ## Bug fixes * `vfold_cv()` now utilizes the `breaks` argument correctly for repeated cross-validation (@ZWael, #471).