From 3b77b682bf46ed2abb063a36181d6737f55deb05 Mon Sep 17 00:00:00 2001 From: Stathis Gennatas Date: Sat, 18 Oct 2025 16:40:15 -0700 Subject: [PATCH] Rename parameter classes for consistency: update 'Params' to 'Config' in Resampler subclasses --- R/04_S7_Resampler.R | 70 ++++++++++++++++----------------- tests/testthat/test_Resampler.R | 58 +++++++++++++-------------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/R/04_S7_Resampler.R b/R/04_S7_Resampler.R index 3509948a..5acefad3 100644 --- a/R/04_S7_Resampler.R +++ b/R/04_S7_Resampler.R @@ -95,16 +95,16 @@ method(desc_alt, ResamplerConfig) <- function(x) { ) } # /rtemis::desc.ResamplerConfig -# KFoldParams ---- -#' @title KFoldParams +# KFoldConfig ---- +#' @title KFoldConfig #' #' @description #' ResamplerConfig subclass for k-fold resampling. #' #' @author EDG #' @noRd -KFoldParams <- new_class( - name = "KFoldParams", +KFoldConfig <- new_class( + name = "KFoldConfig", parent = ResamplerConfig, properties = list( stratify_var = class_character | NULL, @@ -124,18 +124,18 @@ KFoldParams <- new_class( seed = seed ) } -) # /KFoldParams +) # /KFoldConfig -# StratSubParams ---- -#' @title StratSubParams +# StratSubConfig ---- +#' @title StratSubConfig #' #' @description #' ResamplerConfig subclass for stratified subsampling. #' #' @author EDG #' @noRd -StratSubParams <- new_class( - name = "StratSubParams", +StratSubConfig <- new_class( + name = "StratSubConfig", parent = ResamplerConfig, properties = list( n = scalar_int_pos, @@ -165,18 +165,18 @@ StratSubParams <- new_class( seed = seed ) } -) # /StratSubParams +) # /StratSubConfig -# StratBootParams ---- -#' @title StratBootParams +# StratBootConfig ---- +#' @title StratBootConfig #' #' @description #' ResamplerConfig subclass for stratified bootstrapping. #' #' @author EDG #' @noRd -StratBootParams <- new_class( - name = "StratBootParams", +StratBootConfig <- new_class( + name = "StratBootConfig", parent = ResamplerConfig, properties = list( stratify_var = class_character | NULL, @@ -208,18 +208,18 @@ StratBootParams <- new_class( seed = seed ) } -) # /StratBootParams +) # /StratBootConfig -# BootstrapParams ---- -#' @title BootstrapParams +# BootstrapConfig ---- +#' @title BootstrapConfig #' #' @description #' ResamplerConfig subclass for bootstrap resampling. #' #' @author EDG #' @noRd -BootstrapParams <- new_class( - name = "BootstrapParams", +BootstrapConfig <- new_class( + name = "BootstrapConfig", parent = ResamplerConfig, properties = list( id_strat = class_vector | NULL, @@ -235,18 +235,18 @@ BootstrapParams <- new_class( seed = seed ) } -) # /BootstrapParams +) # /BootstrapConfig -# LOOCVParams ---- -#' @title LOOCVParams +# LOOCVConfig ---- +#' @title LOOCVConfig #' #' @description #' ResamplerConfig subclass for leave-one-out cross-validation. #' #' @author EDG #' @noRd -LOOCVParams <- new_class( - name = "LOOCVParams", +LOOCVConfig <- new_class( + name = "LOOCVConfig", parent = ResamplerConfig, constructor = function(n) { new_object( @@ -256,18 +256,18 @@ LOOCVParams <- new_class( ) ) } -) # /LOOCVParams +) # /LOOCVConfig -# CustomParams ---- -#' @title CustomParams +# CustomConfig ---- +#' @title CustomConfig #' #' @description #' ResamplerConfig subclass for custom resampling. #' #' @author EDG #' @noRd -CustomParams <- new_class( - name = "CustomParams", +CustomConfig <- new_class( + name = "CustomConfig", parent = ResamplerConfig, constructor = function(n) { new_object( @@ -277,7 +277,7 @@ CustomParams <- new_class( ) ) } -) # /CustomParams +) # /CustomConfig # setup_Resampler() ---- #' Setup Resampler @@ -324,7 +324,7 @@ setup_Resampler <- function( seed <- clean_int(seed) if (type == "KFold") { - KFoldParams( + KFoldConfig( n = n_resamples, stratify_var = stratify_var, strat_n_bins = strat_n_bins, @@ -332,7 +332,7 @@ setup_Resampler <- function( seed = seed ) } else if (type == "StratSub") { - StratSubParams( + StratSubConfig( n = n_resamples, train_p = train_p, stratify_var = stratify_var, @@ -341,7 +341,7 @@ setup_Resampler <- function( seed = seed ) } else if (type == "StratBoot") { - StratBootParams( + StratBootConfig( n = n_resamples, train_p = train_p, stratify_var = stratify_var, @@ -351,13 +351,13 @@ setup_Resampler <- function( seed = seed ) } else if (type == "Bootstrap") { - BootstrapParams( + BootstrapConfig( n = n_resamples, id_strat = id_strat, seed = seed ) } else if (type == "LOOCV") { - LOOCVParams( + LOOCVConfig( n = NA_integer_ ) } else { diff --git a/tests/testthat/test_Resampler.R b/tests/testthat/test_Resampler.R index f5477a83..e9add75e 100644 --- a/tests/testthat/test_Resampler.R +++ b/tests/testthat/test_Resampler.R @@ -4,9 +4,9 @@ # library(testthat) -# StratSubParams ---- -test_that("StratSubParams succeeds", { - rsp <- StratSubParams( +# StratSubConfig ---- +test_that("StratSubConfig succeeds", { + rsp <- StratSubConfig( n = 10L, stratify_var = NULL, train_p = .75, @@ -14,34 +14,34 @@ test_that("StratSubParams succeeds", { id_strat = NULL, seed = NULL ) - expect_s7_class(rsp, StratSubParams) + expect_s7_class(rsp, StratSubConfig) }) -# KFoldParams ---- -test_that("KFoldParams succeeds", { - rsp <- KFoldParams( +# KFoldConfig ---- +test_that("KFoldConfig succeeds", { + rsp <- KFoldConfig( n = 10L, stratify_var = NULL, strat_n_bins = 4L, id_strat = NULL, seed = NULL ) - expect_s7_class(rsp, KFoldParams) + expect_s7_class(rsp, KFoldConfig) }) -# BootstrapParams ---- -test_that("BootstrapParams succeeds", { - rsp <- BootstrapParams( +# BootstrapConfig ---- +test_that("BootstrapConfig succeeds", { + rsp <- BootstrapConfig( n = 10L, id_strat = NULL, seed = NULL ) - expect_s7_class(rsp, BootstrapParams) + expect_s7_class(rsp, BootstrapConfig) }) -# StratBootParams ---- -test_that("StratBootParams succeeds", { - rsp <- StratBootParams( +# StratBootConfig ---- +test_that("StratBootConfig succeeds", { + rsp <- StratBootConfig( n = 10L, stratify_var = NULL, train_p = .75, @@ -50,23 +50,23 @@ test_that("StratBootParams succeeds", { id_strat = NULL, seed = NULL ) - expect_s7_class(rsp, StratBootParams) + expect_s7_class(rsp, StratBootConfig) }) -# LOOCVParams ---- -test_that("LOOCVParams succeeds", { - rsp <- LOOCVParams( +# LOOCVConfig ---- +test_that("LOOCVConfig succeeds", { + rsp <- LOOCVConfig( n = 10L ) - expect_s7_class(rsp, LOOCVParams) + expect_s7_class(rsp, LOOCVConfig) }) -# CustomParams ---- -test_that("CustomParams succeeds", { - rsp <- CustomParams( +# CustomConfig ---- +test_that("CustomConfig succeeds", { + rsp <- CustomConfig( n = 10L ) - expect_s7_class(rsp, CustomParams) + expect_s7_class(rsp, CustomConfig) }) # setup_Resampler() defaults ---- @@ -78,19 +78,19 @@ test_that("setup_Resampler() succeeds", { # setup_Resampler() kfold ---- test_that("setup_Resampler() kfold succeeds", { rsp <- setup_Resampler(type = "KFold") - expect_s7_class(rsp, KFoldParams) + expect_s7_class(rsp, KFoldConfig) }) # setup_Resampler() strat_sub ---- test_that("setup_Resampler() strat_sub succeeds", { rsp <- setup_Resampler(type = "StratSub") - expect_s7_class(rsp, StratSubParams) + expect_s7_class(rsp, StratSubConfig) }) # setup_Resampler() strat_boot ---- test_that("setup_Resampler() strat_boot succeeds", { rsp <- setup_Resampler(type = "StratBoot") - expect_s7_class(rsp, StratBootParams) + expect_s7_class(rsp, StratBootConfig) }) test_that("setup_Resampler() strat_boot fails with invalid train_p", { @@ -102,13 +102,13 @@ test_that("setup_Resampler() strat_boot fails with invalid train_p", { # setup_Resampler() bootstrap ---- test_that("setup_Resampler() bootstrap succeeds", { rsp <- setup_Resampler(type = "Bootstrap") - expect_s7_class(rsp, BootstrapParams) + expect_s7_class(rsp, BootstrapConfig) }) # setup_Resampler() loocv ---- test_that("setup_Resampler() loocv succeeds", { rsp <- setup_Resampler(type = "LOOCV") - expect_s7_class(rsp, LOOCVParams) + expect_s7_class(rsp, LOOCVConfig) }) # Resampler ----