From 345f9e1d195ca9e9ae2d3ef842d6d844d2a1d2b6 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Thu, 4 Jan 2024 15:44:41 -0800 Subject: [PATCH 1/9] fix typo --- _pkgdown.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index 257968c..4f5cd14 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -8,7 +8,7 @@ template: includes: in_header: | - + reference: - title: Register Models From 10584477d8f6a1161f6460c712141e5e533b6d15 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 10:18:01 -0800 Subject: [PATCH 2/9] update snapshots --- tests/testthat/_snaps/check.md | 65 ++++++---- tests/testthat/_snaps/set_dependency.md | 65 ++++++---- tests/testthat/_snaps/set_encoding.md | 85 +++++++------ tests/testthat/_snaps/set_fit.md | 140 +++++++++++++--------- tests/testthat/_snaps/set_model_arg.md | 85 +++++++------ tests/testthat/_snaps/set_model_engine.md | 50 ++++---- tests/testthat/_snaps/set_model_mode.md | 25 ++-- tests/testthat/_snaps/set_new_model.md | 25 ++-- tests/testthat/_snaps/set_pred.md | 100 +++++++++------- 9 files changed, 384 insertions(+), 256 deletions(-) diff --git a/tests/testthat/_snaps/check.md b/tests/testthat/_snaps/check.md index 0e34609..4b007eb 100644 --- a/tests/testthat/_snaps/check.md +++ b/tests/testthat/_snaps/check.md @@ -2,93 +2,106 @@ Code check_spec_mode_engine_val("hoop", "raw", "stats") - Error - Available modes for engine stats are: 'unknown', 'partition' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for engine stats are: 'unknown', 'partition' # stop_incompatible_mode() works Code stop_incompatible_mode(spec_modes = "partition") - Error - Available modes are: 'partition' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes are: 'partition' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw")) - Error - Available modes are: 'partition', 'raw' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes are: 'partition', 'raw' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw", "another one")) - Error - Available modes are: 'partition', 'raw', 'another one' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes are: 'partition', 'raw', 'another one' --- Code stop_incompatible_mode(spec_modes = "partition", eng = "stats") - Error - Available modes for engine stats are: 'partition' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for engine stats are: 'partition' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw"), eng = "stats") - Error - Available modes for engine stats are: 'partition', 'raw' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for engine stats are: 'partition', 'raw' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw", "another one"), eng = "stats") - Error - Available modes for engine stats are: 'partition', 'raw', 'another one' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for engine stats are: 'partition', 'raw', 'another one' --- Code stop_incompatible_mode(spec_modes = "partition", model = "shallow") - Error - Available modes for model type shallow are: 'partition' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow are: 'partition' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw"), model = "shallow") - Error - Available modes for model type shallow are: 'partition', 'raw' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow are: 'partition', 'raw' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw", "another one"), model = "shallow") - Error - Available modes for model type shallow are: 'partition', 'raw', 'another one' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow are: 'partition', 'raw', 'another one' --- Code stop_incompatible_mode(spec_modes = "partition", eng = "stats", model = "shallow") - Error - Available modes for model type shallow with engine stats are: 'partition' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow with engine stats are: 'partition' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw"), eng = "stats", model = "shallow") - Error - Available modes for model type shallow with engine stats are: 'partition', 'raw' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow with engine stats are: 'partition', 'raw' --- Code stop_incompatible_mode(spec_modes = c("partition", "raw", "another one"), eng = "stats", model = "shallow") - Error - Available modes for model type shallow with engine stats are: 'partition', 'raw', 'another one' + Condition + Error in `stop_incompatible_mode()`: + ! Available modes for model type shallow with engine stats are: 'partition', 'raw', 'another one' diff --git a/tests/testthat/_snaps/set_dependency.md b/tests/testthat/_snaps/set_dependency.md index 46d170b..9187cf3 100644 --- a/tests/testthat/_snaps/set_dependency.md +++ b/tests/testthat/_snaps/set_dependency.md @@ -2,90 +2,103 @@ Code set_dependency("polarbear") - Error - Model `polarbear` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `polarbear` has not been registered. --- Code set_dependency(c("bear", "rabbit"), "partition", "stats", "stats") - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_dependency() errors with wrong `mode` argument Code set_dependency("clip") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_dependency("clip", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_dependency("clip", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_dependency("clip", "not partition", "stats", "stats") - Error - mode 'not partition' is not a valid mode for 'clip'. + Condition + Error in `set_dependency()`: + ! mode 'not partition' is not a valid mode for 'clip'. # set_dependency() errors with wrong `engine` argument Code set_dependency("hamper", "partition") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_dependency("hamper", "partition", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("hamper", "partition", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). # set_dependency() errors with wrong `pkg` argument Code set_dependency("duck", "partition", "stats") - Error - Please supply a single character value for the package name. + Condition + Error in `check_pkg_val()`: + ! Please supply a single character value for the package name. --- Code set_dependency("duck", "partition", "stats", c("glmnet", "stats")) - Error - Please supply a single character value for the package name. + Condition + Error in `check_pkg_val()`: + ! Please supply a single character value for the package name. --- Code set_dependency("duck", "partition", "stats", NULL) - Error - Please supply a single character value for the package name. + Condition + Error in `check_pkg_val()`: + ! Please supply a single character value for the package name. # set_dependency() errors if engine doesn't match Code set_dependency("zebra", "partition", "not stats", "base") - Error - The engine 'not stats' has not been registered for model 'zebra'. + Condition + Error in `set_dependency()`: + ! The engine 'not stats' has not been registered for model 'zebra'. diff --git a/tests/testthat/_snaps/set_encoding.md b/tests/testthat/_snaps/set_encoding.md index 1cfebdb..0c20678 100644 --- a/tests/testthat/_snaps/set_encoding.md +++ b/tests/testthat/_snaps/set_encoding.md @@ -2,8 +2,9 @@ Code set_encoding("light") - Error - Model `light` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `light` has not been registered. --- @@ -11,29 +12,33 @@ set_encoding(model = c("bear", "rabbit"), mode = "partition", eng = "stats", options = list(predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE)) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_encoding() errors with wrong `mode` argument Code set_encoding("sticker") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_encoding("sticker", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_encoding("sticker", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -41,51 +46,58 @@ set_encoding(model = "sticker", mode = "not partition", eng = "stats", options = list( predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE)) - Error - 'not partition' is not a known mode for model `sticker()`. + Condition + Error in `check_spec_mode_engine_val()`: + ! 'not partition' is not a known mode for model `sticker()`. # set_encoding() errors with wrong `engine` argument Code set_encoding("lantern", "partition") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_encoding("lantern", "partition", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("lantern", "partition", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). # set_encoding() errors with wrong `value` argument Code set_encoding("chain", "partition", "stats") - Error - `values` should be a list. + Condition + Error in `check_encodings()`: + ! `values` should be a list. --- Code set_encoding("chain", "partition", "stats", NULL) - Error - `values` should be a list. + Condition + Error in `check_encodings()`: + ! `values` should be a list. --- Code set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE)) - Error - The values passed to `set_encoding()` are missing arguments: 'predictor_indicators' + Condition + Error in `check_encodings()`: + ! The values passed to `set_encoding()` are missing arguments: 'predictor_indicators' --- @@ -93,8 +105,9 @@ set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( predictor_indicators = "traditional", remove_intercept = TRUE, allow_sparse_x = FALSE)) - Error - The values passed to `set_encoding()` are missing arguments: 'compute_intercept' + Condition + Error in `check_encodings()`: + ! The values passed to `set_encoding()` are missing arguments: 'compute_intercept' --- @@ -102,8 +115,9 @@ set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( predictor_indicators = "traditional", compute_intercept = TRUE, allow_sparse_x = FALSE)) - Error - The values passed to `set_encoding()` are missing arguments: 'remove_intercept' + Condition + Error in `check_encodings()`: + ! The values passed to `set_encoding()` are missing arguments: 'remove_intercept' --- @@ -111,8 +125,9 @@ set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE)) - Error - The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x' + Condition + Error in `check_encodings()`: + ! The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x' --- @@ -120,8 +135,9 @@ set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE, additional = "arg")) - Error - The values passed to `set_encoding()` had extra arguments: 'additional' + Condition + Error in `check_encodings()`: + ! The values passed to `set_encoding()` had extra arguments: 'additional' # is_discordant_info() triggers for set_encoding() @@ -129,6 +145,7 @@ set_encoding(model = "longs", mode = "partition", eng = "stats", options = list( predictor_indicators = "traditional", compute_intercept = FALSE, remove_intercept = TRUE, allow_sparse_x = FALSE)) - Error - The combination of engine 'stats' and mode 'partition' already has encoding data for model 'longs' and the new information being registered is different. + Condition + Error in `is_discordant_info()`: + ! The combination of engine 'stats' and mode 'partition' already has encoding data for model 'longs' and the new information being registered is different. diff --git a/tests/testthat/_snaps/set_fit.md b/tests/testthat/_snaps/set_fit.md index 302f875..53a54d0 100644 --- a/tests/testthat/_snaps/set_fit.md +++ b/tests/testthat/_snaps/set_fit.md @@ -4,15 +4,17 @@ set_fit(model = "tape", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - The combination of 'stats' and mode 'partition' already has a fit component for model 'tape'. + Condition + Error in `set_fit()`: + ! The combination of 'stats' and mode 'partition' already has a fit component for model 'tape'. # set_fit() errors with wrong `model` argument Code set_fit("light") - Error - Model `light` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `light` has not been registered. --- @@ -20,29 +22,33 @@ set_fit(model = c("bear", "rabbit"), mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_fit() errors with wrong `mode` argument Code set_fit("camcorder") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_fit("camcorder", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_fit("camcorder", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -50,43 +56,49 @@ set_fit(model = "camcorder", mode = "not partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - 'not partition' is not a known mode for model `camcorder()`. + Condition + Error in `check_spec_mode_engine_val()`: + ! 'not partition' is not a known mode for model `camcorder()`. # set_fit() errors with wrong `engine` argument Code set_fit("dice", "partition") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_fit("dice", "partition", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("dice", "partition", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). # set_fit() errors with wrong `value` argument Code set_fit("ladle", "partition", "stats") - Error - The `fit` module cannot be NULL. + Condition + Error in `check_fit_info()`: + ! The `fit` module cannot be NULL. --- Code set_fit("ladle", "partition", "stats", NULL) - Error - The `fit` module cannot be NULL. + Condition + Error in `check_fit_info()`: + ! The `fit` module cannot be NULL. --- @@ -94,24 +106,27 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` + Condition + Error in `check_fit_info()`: + ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- Code set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` + Condition + Error in `check_fit_info()`: + ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- Code set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), defaults = list())) - Error - The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` + Condition + Error in `check_fit_info()`: + ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -119,8 +134,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"))) - Error - The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` + Condition + Error in `check_fit_info()`: + ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -128,8 +144,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list(), additional = "arg")) - Error - The `fit` module can only have optional elements: `data` + Condition + Error in `check_fit_info()`: + ! The `fit` module can only have optional elements: `data` --- @@ -137,8 +154,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list(), data = list("not", "named"))) - Error - All elements of the `data` argument vector must be named. + Condition + Error in `check_fit_info()`: + ! All elements of the `data` argument vector must be named. --- @@ -146,8 +164,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "not formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` + Condition + Error in `check_interface_val()`: + ! The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` --- @@ -155,8 +174,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = c("formula", "matrix"), protect = c("formula", "data"), func = c( pkg = "stats", fun = "lm"), defaults = list())) - Error - The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` + Condition + Error in `check_interface_val()`: + ! The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` --- @@ -164,8 +184,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c("stats", "lm"), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -173,8 +194,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c("stats", pkg = "lm"), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -182,8 +204,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(fun = "stats", pkg = "lm", additional = "no"), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -191,8 +214,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(fun = lm, pkg = "lm"), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -200,8 +224,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(fun = "stats", pkg = lm), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -209,8 +234,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = NULL)) - Error - The `defaults` element should be a list: + Condition + Error in `check_fit_info()`: + ! The `defaults` element should be a list: --- @@ -218,8 +244,9 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats"), defaults = list())) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. # set_fit() errors if engine doesn't match @@ -227,6 +254,7 @@ set_fit(model = "whale", mode = "partition", eng = "not stats", value = list( interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) - Error - Engine 'not stats' is not supported for `whale()`. See `show_engines('whale')`. + Condition + Error in `check_spec_mode_engine_val()`: + ! Engine 'not stats' is not supported for `whale()`. See `show_engines('whale')`. diff --git a/tests/testthat/_snaps/set_model_arg.md b/tests/testthat/_snaps/set_model_arg.md index 352846d..a7fe749 100644 --- a/tests/testthat/_snaps/set_model_arg.md +++ b/tests/testthat/_snaps/set_model_arg.md @@ -2,124 +2,141 @@ Code set_model_arg("light") - Error - Model `light` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `light` has not been registered. --- Code set_model_arg(model = c("phone", "sock")) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_model_arg() errors with wrong `engine` argument Code set_model_arg("thermos") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_arg("thermos", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_arg("thermos", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). # set_model_arg() errors with wrong `exposed` argument Code set_model_arg(model = "marker", eng = "stats") - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. --- Code set_model_arg(model = "marker", eng = "stats", exposed = c("glmnet", "stats")) - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. --- Code set_model_arg(model = "marker", eng = "stats", exposed = NULL) - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. # set_model_arg() errors with wrong `original` argument Code set_model_arg(model = "mustache", eng = "stats", exposed = "method") - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. --- Code set_model_arg(model = "mustache", eng = "stats", exposed = "method", original = c( "not", "method")) - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. --- Code set_model_arg(model = "mustache", eng = "stats", exposed = "method", original = NULL) - Error - Please supply a character string for the argument. + Condition + Error in `check_arg_val()`: + ! Please supply a character string for the argument. # set_model_arg() errors with wrong `func` argument Code set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "moethod") - Error - argument "func" is missing, with no default + Condition + Error in `set_model_arg()`: + ! argument "func" is missing, with no default --- Code set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "method", func = c("not", "method")) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- Code set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "method", func = NULL) - Error - `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. + Condition + Error in `check_func_val()`: + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. # set_model_arg() errors with wrong `has_submodel` argument Code set_model_arg(model = "velcro", eng = "stats", exposed = "method", original = "moethod", func = list(pkg = "stats", fun = "lm")) - Error - argument "has_submodel" is missing, with no default + Condition + Error in `set_model_arg()`: + ! argument "has_submodel" is missing, with no default --- Code set_model_arg(model = "velcro", eng = "stats", exposed = "method", original = "method", func = list(pkg = "stats", fun = "lm"), has_submodel = "yes") - Error - The `submodels` argument should be a single logical. + Condition + Error in `check_submodels_val()`: + ! The `submodels` argument should be a single logical. --- Code set_model_arg(model = "velcro", eng = "stats", exposed = "method", original = "method", func = list(pkg = "stats", fun = "lm"), has_submodel = NULL) - Error - The `submodels` argument should be a single logical. + Condition + Error in `check_submodels_val()`: + ! The `submodels` argument should be a single logical. diff --git a/tests/testthat/_snaps/set_model_engine.md b/tests/testthat/_snaps/set_model_engine.md index 08ebbfe..916ea1f 100644 --- a/tests/testthat/_snaps/set_model_engine.md +++ b/tests/testthat/_snaps/set_model_engine.md @@ -2,69 +2,79 @@ Code set_model_engine("panda", "partition", "stats") - Error - Engine 'stats' already exists for `panda()` with mode `partition`. + Condition + Error in `check_mode_for_new_engine()`: + ! Engine 'stats' already exists for `panda()` with mode `partition`. # set_model_engine() errors with wrong `model` argument Code set_model_engine("stickynotes") - Error - Model `stickynotes` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `stickynotes` has not been registered. --- Code set_model_engine(c("boombox", "egg"), "partition", "stats") - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_model_engine() errors with wrong `mode` argument Code set_model_engine("paper") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_model_engine("paper", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_model_engine("paper", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_model_engine("panda", "not partition", "stats") - Error - 'not partition' is not a known mode for model `panda()`. + Condition + Error in `check_mode_for_new_engine()`: + ! 'not partition' is not a known mode for model `panda()`. # set_model_engine() errors with wrong `engine` argument Code set_model_engine("street", "partition") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("street", "partition", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("street", "partition", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). diff --git a/tests/testthat/_snaps/set_model_mode.md b/tests/testthat/_snaps/set_model_mode.md index 07f5cd8..3b60bbb 100644 --- a/tests/testthat/_snaps/set_model_mode.md +++ b/tests/testthat/_snaps/set_model_mode.md @@ -2,34 +2,39 @@ Code set_model_mode("wagon") - Error - Model `wagon` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `wagon` has not been registered. --- Code set_model_mode(c("boombox", "egg"), "classification") - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_model_mode() errors with wrong `mode` argument Code set_model_mode("glass") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_model_mode("glass", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_model_mode("glass", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). diff --git a/tests/testthat/_snaps/set_new_model.md b/tests/testthat/_snaps/set_new_model.md index 4bb9e71..0b88e8d 100644 --- a/tests/testthat/_snaps/set_new_model.md +++ b/tests/testthat/_snaps/set_new_model.md @@ -2,34 +2,39 @@ Code set_new_model() - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `set_new_model()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). --- Code set_new_model(2) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `set_new_model()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). --- Code set_new_model(letters[1:2]) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `set_new_model()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_env_val() errors currectly Code set_env_val(c("models", "modes"), NULL) - Error - `name` should be a single character value. + Condition + Error in `set_env_val()`: + ! `name` should be a single character value. --- Code set_env_val(1, NULL) - Error - `name` should be a single character value. + Condition + Error in `set_env_val()`: + ! `name` should be a single character value. diff --git a/tests/testthat/_snaps/set_pred.md b/tests/testthat/_snaps/set_pred.md index 8b230f6..7e92204 100644 --- a/tests/testthat/_snaps/set_pred.md +++ b/tests/testthat/_snaps/set_pred.md @@ -2,8 +2,9 @@ Code set_pred("light") - Error - Model `light` has not been registered. + Condition + Error in `check_model_val()`: + ! Model `light` has not been registered. --- @@ -11,29 +12,33 @@ set_pred(model = c("tent", "shed"), mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - Please supply a character string for a model name (e.g. `'k_means'`). + Condition + Error in `check_model_val()`: + ! Please supply a character string for a model name (e.g. `'k_means'`). # set_pred() errors with wrong `mode` argument Code set_pred("game") - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_pred("game", c("classification", "regression")) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- Code set_pred("game", NULL) - Error - Please supply a character string for a mode (e.g. `'partition'`). + Condition + Error in `check_mode_val()`: + ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -41,43 +46,49 @@ set_pred(model = "game", mode = "not partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - 'not partition' is not a known mode for model `game()`. + Condition + Error in `check_spec_mode_engine_val()`: + ! 'not partition' is not a known mode for model `game()`. # set_pred() errors with wrong `engine` argument Code set_pred("dog", "partition") - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_pred("dog", "partition", c("glmnet", "stats")) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). --- Code set_model_engine("dog", "partition", NULL) - Error - Please supply a character string for an engine name (e.g. `'stats'`). + Condition + Error in `check_eng_val()`: + ! Please supply a character string for an engine name (e.g. `'stats'`). # set_pred() errors with wrong `value` argument Code set_pred("trunk", "partition", "stats", "raw") - Error - argument "value" is missing, with no default + Condition + Error in `set_pred()`: + ! argument "value" is missing, with no default --- Code set_pred("trunk", "partition", "stats", "raw", NULL) - Error - The `predict` module should have elements: `args`, `func`, `post`, `pre` + Condition + Error in `check_pred_info()`: + ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -85,8 +96,9 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(post = NULL, func = c(fun = "predict"), args = list(object = rlang::expr( object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The `predict` module should have elements: `args`, `func`, `post`, `pre` + Condition + Error in `check_pred_info()`: + ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -94,8 +106,9 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, func = c(fun = "predict"), args = list(object = rlang::expr( object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The `predict` module should have elements: `args`, `func`, `post`, `pre` + Condition + Error in `check_pred_info()`: + ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -103,16 +116,18 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, args = list(object = rlang::expr(object$ fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The `predict` module should have elements: `args`, `func`, `post`, `pre` + Condition + Error in `check_pred_info()`: + ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- Code set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"))) - Error - The `predict` module should have elements: `args`, `func`, `post`, `pre` + Condition + Error in `check_pred_info()`: + ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -120,8 +135,9 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = "NULL", post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The `pre` module should be null or a function: + Condition + Error in `check_pred_info()`: + ! The `pre` module should be null or a function: --- @@ -129,16 +145,18 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = "NULL", func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The `post` module should be null or a function: + Condition + Error in `check_pred_info()`: + ! The `post` module should be null or a function: --- Code set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = "not a list")) - Error - The `args` element should be a list. + Condition + Error in `check_pred_info()`: + ! The `args` element should be a list. # set_pred() errors with wrong `type` argument @@ -146,8 +164,9 @@ set_pred(model = "scroll", mode = "partition", eng = "stats", type = "not raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The prediction type should be one of: 'cluster', 'raw' + Condition + Error in `check_pred_info()`: + ! The prediction type should be one of: 'cluster', 'raw' # is_discordant_info() triggers for set_pred() @@ -155,6 +174,7 @@ set_pred(model = "diamond", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "not predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) - Error - The combination of engine 'stats' and mode 'partition' and prediction type 'raw' already has predict data for model 'diamond' and the new information being registered is different. + Condition + Error in `is_discordant_info()`: + ! The combination of engine 'stats' and mode 'partition' and prediction type 'raw' already has predict data for model 'diamond' and the new information being registered is different. From 2eceffe3842a2c695f7d5b4139a623e45efe94e6 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 11:01:52 -0800 Subject: [PATCH 3/9] pass around calls --- R/check.R | 32 ++++++++++++++++++++++---------- R/set_dependency.R | 7 +++++-- R/set_encoding.R | 16 ++++++++++------ R/set_fit.R | 37 +++++++++++++++++++++---------------- R/set_model_arg.R | 14 ++++++++++---- R/set_model_engine.R | 9 ++++++--- R/set_pred.R | 20 ++++++++++++++------ 7 files changed, 88 insertions(+), 47 deletions(-) diff --git a/R/check.R b/R/check.R index c51a204..a9dfda5 100644 --- a/R/check.R +++ b/R/check.R @@ -9,7 +9,9 @@ #' library(rlang) #' tmp <- catch_cnd(stop_incompatible_mode("partition")) #' @export -stop_incompatible_mode <- function(spec_modes, eng = NULL, model = NULL) { +stop_incompatible_mode <- function(spec_modes, + eng = NULL, + model = NULL) { if (is.null(eng) & is.null(model)) { msg <- "Available modes are: " } @@ -32,7 +34,7 @@ stop_incompatible_mode <- function(spec_modes, eng = NULL, model = NULL) { rlang::abort(msg) } -check_model_val <- function(model) { +check_model_val <- function(model, call = rlang::caller_env()) { if (rlang::is_missing(model) || length(model) != 1 || !is.character(model)) { rlang::abort( "Please supply a character string for a model name (e.g. `'k_means'`)." @@ -42,25 +44,30 @@ check_model_val <- function(model) { current <- get_model_env() if (!any(current$models == model)) { - rlang::abort(glue::glue("Model `{model}` has not been registered.")) + rlang::abort( + glue::glue("Model `{model}` has not been registered."), + call = call + ) } invisible(NULL) } -check_mode_val <- function(mode) { +check_mode_val <- function(mode, call = rlang::caller_env()) { if (rlang::is_missing(mode) || length(mode) != 1 || !is.character(mode)) { rlang::abort( - "Please supply a character string for a mode (e.g. `'partition'`)." + "Please supply a character string for a mode (e.g. `'partition'`).", + call = call ) } invisible(NULL) } -check_eng_val <- function(eng) { +check_eng_val <- function(eng, call = rlang::caller_env()) { if (rlang::is_missing(eng) || length(eng) != 1 || !is.character(eng)) { rlang::abort( - "Please supply a character string for an engine name (e.g. `'stats'`)." + "Please supply a character string for an engine name (e.g. `'stats'`).", + call = call ) } invisible(NULL) @@ -79,11 +86,15 @@ check_eng_val <- function(eng) { #' library(rlang) #' tmp <- catch_cnd(check_spec_mode_engine_val("turtle", "partition", "vegan")) #' @export -check_spec_mode_engine_val <- function(model, mode, eng) { +check_spec_mode_engine_val <- function(model, + mode, + eng, + call = rlang::caller_env()) { all_modes <- get_from_env(paste0(model, "_modes")) if (!(mode %in% all_modes)) { rlang::abort( - glue::glue("'{mode}' is not a known mode for model `{model}()`.") + glue::glue("'{mode}' is not a known mode for model `{model}()`."), + call = call ) } @@ -99,7 +110,8 @@ check_spec_mode_engine_val <- function(model, mode, eng) { paste0( "Engine '", eng, "' is not supported for `", model, "()`. See ", "`show_engines('", model, "')`." - ) + ), + call = call ) } diff --git a/R/set_dependency.R b/R/set_dependency.R index dfd87f3..7b713cc 100644 --- a/R/set_dependency.R +++ b/R/set_dependency.R @@ -113,9 +113,12 @@ get_dependency <- function(model) { rlang::env_get(get_model_env(), pkg_name) } -check_pkg_val <- function(pkg) { +check_pkg_val <- function(pkg, call = rlang::caller_env()) { if (rlang::is_missing(pkg) || length(pkg) != 1 || !is.character(pkg)) { - rlang::abort("Please supply a single character value for the package name.") + rlang::abort( + "Please supply a single character value for the package name.", + call = call + ) } invisible(NULL) } diff --git a/R/set_encoding.R b/R/set_encoding.R index 6acae36..0a95081 100644 --- a/R/set_encoding.R +++ b/R/set_encoding.R @@ -91,9 +91,9 @@ get_encoding <- function(model) { get_from_env(nm) } -check_encodings <- function(x) { +check_encodings <- function(x, call = rlang::caller_env()) { if (rlang::is_missing(x) || !is.list(x)) { - rlang::abort("`values` should be a list.") + rlang::abort("`values` should be a list.", call = call) } req_args <- list( predictor_indicators = rlang::na_chr, @@ -108,7 +108,8 @@ check_encodings <- function(x) { glue::glue( "The values passed to `set_encoding()` are missing arguments: ", paste0("'", missing_args, "'", collapse = ", ") - ) + ), + call = call ) } extra_args <- setdiff(names(x), names(req_args)) @@ -117,14 +118,16 @@ check_encodings <- function(x) { glue::glue( "The values passed to `set_encoding()` had extra arguments: ", paste0("'", extra_args, "'", collapse = ", ") - ) + ), + call = call ) } invisible(x) } is_discordant_info <- function(model, mode, eng, candidate, - pred_type = NULL, component = "fit") { + pred_type = NULL, component = "fit", + call = rlang::caller_env()) { current <- get_from_env(paste0(model, "_", component)) if (is.null(current)) { return(TRUE) @@ -153,7 +156,8 @@ is_discordant_info <- function(model, mode, eng, candidate, "The combination of engine '{eng}' and mode '{mode}' {p_type} already ", "has {component} data for model '{model}' and the new information ", "being registered is different." - ) + ), + call = call ) } diff --git a/R/set_fit.R b/R/set_fit.R index f5b2d5a..ebcb5d3 100644 --- a/R/set_fit.R +++ b/R/set_fit.R @@ -95,9 +95,9 @@ get_fit <- function(model) { rlang::env_get(get_model_env(), fit_name) } -check_fit_info <- function(fit_obj) { +check_fit_info <- function(fit_obj, call = rlang::caller_env()) { if (rlang::is_missing(fit_obj) || is.null(fit_obj)) { - rlang::abort("The `fit` module cannot be NULL.") + rlang::abort("The `fit` module cannot be NULL.", call = call) } # check required data elements @@ -109,7 +109,8 @@ check_fit_info <- function(fit_obj) { glue::glue( "The `fit` module should have elements: ", glue::glue_collapse(glue::glue("`{exp_nms}`"), sep = ", ") - ) + ), + call = call ) } @@ -123,40 +124,44 @@ check_fit_info <- function(fit_obj) { glue::glue_collapse(glue::glue("`{opt_nms}`"), sep = ", ") ) - rlang::abort(msg) + rlang::abort(msg, call = call) } if (any(other_nms == "data")) { data_nms <- names(fit_obj$data) if (length(data_nms) == 0 || any(data_nms == "")) { - rlang::abort("All elements of the `data` argument vector must be named.") + rlang::abort( + "All elements of the `data` argument vector must be named.", + call = call + ) } } - check_interface_val(fit_obj$interface) - check_func_val(fit_obj$func) + check_interface_val(fit_obj$interface, call = call) + check_func_val(fit_obj$func, call = call) if (!is.list(fit_obj$defaults)) { - rlang::abort("The `defaults` element should be a list: ") + rlang::abort("The `defaults` element should be a list: ", call = call) } invisible(NULL) } -check_interface_val <- function(x) { +check_interface_val <- function(x, call = rlang::caller_env()) { exp_interf <- c("data.frame", "formula", "matrix") if (length(x) != 1 || !(x %in% exp_interf)) { rlang::abort( glue::glue( "The `interface` element should have a single value of: ", glue::glue_collapse(glue::glue("`{exp_interf}`"), sep = ", ") - ) + ), + call = call ) } invisible(NULL) } -check_func_val <- function(func) { +check_func_val <- function(func, call = rlang::caller_env()) { msg <- paste( "`func` should be a named vector with element 'fun' and the optional ", @@ -167,27 +172,27 @@ check_func_val <- function(func) { nms <- sort(names(func)) if (all(is.null(nms))) { - rlang::abort(msg) + rlang::abort(msg, call = call) } if (length(func) == 1) { if (isTRUE(any(nms != "fun"))) { - rlang::abort(msg) + rlang::abort(msg, call = call) } } else { # check for extra names: allow_nms <- c("fun", "pkg", "range", "trans", "values") not_allowed <- nms[!(nms %in% allow_nms)] if (length(not_allowed) > 0) { - rlang::abort(msg) + rlang::abort(msg, call = call) } } if (!is.character(func[["fun"]])) { - rlang::abort(msg) + rlang::abort(msg, call = call) } if (any(nms == "pkg") && !is.character(func[["pkg"]])) { - rlang::abort(msg) + rlang::abort(msg, call = call) } invisible(NULL) diff --git a/R/set_model_arg.R b/R/set_model_arg.R index f59af06..0cc07ed 100644 --- a/R/set_model_arg.R +++ b/R/set_model_arg.R @@ -76,16 +76,22 @@ get_model_arg <- function(model, eng) { args } -check_arg_val <- function(arg) { +check_arg_val <- function(arg, call = rlang::caller_env()) { if (rlang::is_missing(arg) || length(arg) != 1 || !is.character(arg)) { - rlang::abort("Please supply a character string for the argument.") + rlang::abort( + "Please supply a character string for the argument.", + call = call + ) } invisible(NULL) } -check_submodels_val <- function(has_submodel) { +check_submodels_val <- function(has_submodel, call = rlang::caller_env()) { if (!is.logical(has_submodel) || length(has_submodel) != 1) { - rlang::abort("The `submodels` argument should be a single logical.") + rlang::abort( + "The `submodels` argument should be a single logical.", + call = call + ) } invisible(NULL) } diff --git a/R/set_model_engine.R b/R/set_model_engine.R index 39cf9e8..2e7f731 100644 --- a/R/set_model_engine.R +++ b/R/set_model_engine.R @@ -38,13 +38,15 @@ set_model_engine <- function(model, mode, eng) { invisible(NULL) } -check_mode_for_new_engine <- function(model, eng, mode) { +check_mode_for_new_engine <- function(model, eng, mode, + call = rlang::caller_env()) { all_modes <- get_from_env(paste0(model, "_modes")) if (!(mode %in% all_modes)) { rlang::abort( glue::glue( "'{mode}' is not a known mode for model `{model}()`." - ) + ), + call = call ) } @@ -55,7 +57,8 @@ check_mode_for_new_engine <- function(model, eng, mode) { rlang::abort( glue::glue( "Engine '{eng}' already exists for `{model}()` with mode `{mode}`." - ) + ), + call = call ) } diff --git a/R/set_pred.R b/R/set_pred.R index c30469d..761d013 100644 --- a/R/set_pred.R +++ b/R/set_pred.R @@ -102,13 +102,14 @@ get_pred_type <- function(model, type) { vctrs::vec_slice(all_preds, all_preds$type == type) } -check_pred_info <- function(pred_obj, type) { +check_pred_info <- function(pred_obj, type, call = rlang::caller_env()) { if (all(type != pred_types)) { rlang::abort( glue::glue( "The prediction type should be one of: ", glue::glue_collapse(glue::glue("'{pred_types}'"), sep = ", ") - ) + ), + call = call ) } @@ -118,21 +119,28 @@ check_pred_info <- function(pred_obj, type) { glue::glue( "The `predict` module should have elements: ", glue::glue_collapse(glue::glue("`{exp_nms}`"), sep = ", ") - ) + ), + call = call ) } if (!is.null(pred_obj$pre) & !is.function(pred_obj$pre)) { - rlang::abort("The `pre` module should be null or a function: ") + rlang::abort( + "The `pre` module should be null or a function: ", + call = call + ) } if (!is.null(pred_obj$post) & !is.function(pred_obj$post)) { - rlang::abort("The `post` module should be null or a function: ") + rlang::abort( + "The `post` module should be null or a function: ", + call = call + ) } check_func_val(pred_obj$func) if (!is.list(pred_obj$args)) { - rlang::abort("The `args` element should be a list.") + rlang::abort("The `args` element should be a list.", call = call) } invisible(NULL) From 929f5982fefd79195081fc6d40d4582f395b09ea Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 11:02:01 -0800 Subject: [PATCH 4/9] update snapshots --- tests/testthat/_snaps/set_dependency.md | 20 ++++----- tests/testthat/_snaps/set_encoding.md | 32 +++++++------- tests/testthat/_snaps/set_fit.md | 52 +++++++++++------------ tests/testthat/_snaps/set_model_arg.md | 28 ++++++------ tests/testthat/_snaps/set_model_engine.md | 18 ++++---- tests/testthat/_snaps/set_model_mode.md | 8 ++-- tests/testthat/_snaps/set_pred.md | 36 ++++++++-------- 7 files changed, 97 insertions(+), 97 deletions(-) diff --git a/tests/testthat/_snaps/set_dependency.md b/tests/testthat/_snaps/set_dependency.md index 9187cf3..7175709 100644 --- a/tests/testthat/_snaps/set_dependency.md +++ b/tests/testthat/_snaps/set_dependency.md @@ -3,7 +3,7 @@ Code set_dependency("polarbear") Condition - Error in `check_model_val()`: + Error in `set_dependency()`: ! Model `polarbear` has not been registered. --- @@ -19,7 +19,7 @@ Code set_dependency("clip") Condition - Error in `check_mode_val()`: + Error in `set_dependency()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -27,7 +27,7 @@ Code set_dependency("clip", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_dependency()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -35,7 +35,7 @@ Code set_dependency("clip", NULL) Condition - Error in `check_mode_val()`: + Error in `set_dependency()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -51,7 +51,7 @@ Code set_dependency("hamper", "partition") Condition - Error in `check_eng_val()`: + Error in `set_dependency()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -59,7 +59,7 @@ Code set_dependency("hamper", "partition", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_dependency()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -67,7 +67,7 @@ Code set_model_engine("hamper", "partition", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). # set_dependency() errors with wrong `pkg` argument @@ -75,7 +75,7 @@ Code set_dependency("duck", "partition", "stats") Condition - Error in `check_pkg_val()`: + Error in `set_dependency()`: ! Please supply a single character value for the package name. --- @@ -83,7 +83,7 @@ Code set_dependency("duck", "partition", "stats", c("glmnet", "stats")) Condition - Error in `check_pkg_val()`: + Error in `set_dependency()`: ! Please supply a single character value for the package name. --- @@ -91,7 +91,7 @@ Code set_dependency("duck", "partition", "stats", NULL) Condition - Error in `check_pkg_val()`: + Error in `set_dependency()`: ! Please supply a single character value for the package name. # set_dependency() errors if engine doesn't match diff --git a/tests/testthat/_snaps/set_encoding.md b/tests/testthat/_snaps/set_encoding.md index 0c20678..6a75f33 100644 --- a/tests/testthat/_snaps/set_encoding.md +++ b/tests/testthat/_snaps/set_encoding.md @@ -3,7 +3,7 @@ Code set_encoding("light") Condition - Error in `check_model_val()`: + Error in `set_encoding()`: ! Model `light` has not been registered. --- @@ -21,7 +21,7 @@ Code set_encoding("sticker") Condition - Error in `check_mode_val()`: + Error in `set_encoding()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -29,7 +29,7 @@ Code set_encoding("sticker", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_encoding()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -37,7 +37,7 @@ Code set_encoding("sticker", NULL) Condition - Error in `check_mode_val()`: + Error in `set_encoding()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -47,7 +47,7 @@ predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE)) Condition - Error in `check_spec_mode_engine_val()`: + Error in `set_encoding()`: ! 'not partition' is not a known mode for model `sticker()`. # set_encoding() errors with wrong `engine` argument @@ -55,7 +55,7 @@ Code set_encoding("lantern", "partition") Condition - Error in `check_eng_val()`: + Error in `set_encoding()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -63,7 +63,7 @@ Code set_encoding("lantern", "partition", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_encoding()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -71,7 +71,7 @@ Code set_model_engine("lantern", "partition", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). # set_encoding() errors with wrong `value` argument @@ -79,7 +79,7 @@ Code set_encoding("chain", "partition", "stats") Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! `values` should be a list. --- @@ -87,7 +87,7 @@ Code set_encoding("chain", "partition", "stats", NULL) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! `values` should be a list. --- @@ -96,7 +96,7 @@ set_encoding(model = "chain", mode = "partition", eng = "stats", options = list( compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE)) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! The values passed to `set_encoding()` are missing arguments: 'predictor_indicators' --- @@ -106,7 +106,7 @@ predictor_indicators = "traditional", remove_intercept = TRUE, allow_sparse_x = FALSE)) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! The values passed to `set_encoding()` are missing arguments: 'compute_intercept' --- @@ -116,7 +116,7 @@ predictor_indicators = "traditional", compute_intercept = TRUE, allow_sparse_x = FALSE)) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! The values passed to `set_encoding()` are missing arguments: 'remove_intercept' --- @@ -126,7 +126,7 @@ predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE)) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x' --- @@ -136,7 +136,7 @@ predictor_indicators = "traditional", compute_intercept = TRUE, remove_intercept = TRUE, allow_sparse_x = FALSE, additional = "arg")) Condition - Error in `check_encodings()`: + Error in `set_encoding()`: ! The values passed to `set_encoding()` had extra arguments: 'additional' # is_discordant_info() triggers for set_encoding() @@ -146,6 +146,6 @@ predictor_indicators = "traditional", compute_intercept = FALSE, remove_intercept = TRUE, allow_sparse_x = FALSE)) Condition - Error in `is_discordant_info()`: + Error in `set_encoding()`: ! The combination of engine 'stats' and mode 'partition' already has encoding data for model 'longs' and the new information being registered is different. diff --git a/tests/testthat/_snaps/set_fit.md b/tests/testthat/_snaps/set_fit.md index 53a54d0..327fb37 100644 --- a/tests/testthat/_snaps/set_fit.md +++ b/tests/testthat/_snaps/set_fit.md @@ -13,7 +13,7 @@ Code set_fit("light") Condition - Error in `check_model_val()`: + Error in `set_fit()`: ! Model `light` has not been registered. --- @@ -31,7 +31,7 @@ Code set_fit("camcorder") Condition - Error in `check_mode_val()`: + Error in `set_fit()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -39,7 +39,7 @@ Code set_fit("camcorder", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_fit()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -47,7 +47,7 @@ Code set_fit("camcorder", NULL) Condition - Error in `check_mode_val()`: + Error in `set_fit()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -57,7 +57,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_spec_mode_engine_val()`: + Error in `set_fit()`: ! 'not partition' is not a known mode for model `camcorder()`. # set_fit() errors with wrong `engine` argument @@ -65,7 +65,7 @@ Code set_fit("dice", "partition") Condition - Error in `check_eng_val()`: + Error in `set_fit()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -73,7 +73,7 @@ Code set_fit("dice", "partition", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_fit()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -81,7 +81,7 @@ Code set_model_engine("dice", "partition", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). # set_fit() errors with wrong `value` argument @@ -89,7 +89,7 @@ Code set_fit("ladle", "partition", "stats") Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module cannot be NULL. --- @@ -97,7 +97,7 @@ Code set_fit("ladle", "partition", "stats", NULL) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module cannot be NULL. --- @@ -107,7 +107,7 @@ protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -116,7 +116,7 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", func = c(pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -125,7 +125,7 @@ set_fit(model = "ladle", mode = "partition", eng = "stats", value = list( interface = "formula", protect = c("formula", "data"), defaults = list())) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -135,7 +135,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"))) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module should have elements: `defaults`, `func`, `interface`, `protect` --- @@ -145,7 +145,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list(), additional = "arg")) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `fit` module can only have optional elements: `data` --- @@ -155,7 +155,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list(), data = list("not", "named"))) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! All elements of the `data` argument vector must be named. --- @@ -165,7 +165,7 @@ interface = "not formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_interface_val()`: + Error in `set_fit()`: ! The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` --- @@ -175,7 +175,7 @@ interface = c("formula", "matrix"), protect = c("formula", "data"), func = c( pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_interface_val()`: + Error in `set_fit()`: ! The `interface` element should have a single value of: `data.frame`, `formula`, `matrix` --- @@ -185,7 +185,7 @@ interface = "formula", protect = c("formula", "data"), func = c("stats", "lm"), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -195,7 +195,7 @@ interface = "formula", protect = c("formula", "data"), func = c("stats", pkg = "lm"), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -205,7 +205,7 @@ interface = "formula", protect = c("formula", "data"), func = c(fun = "stats", pkg = "lm", additional = "no"), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -215,7 +215,7 @@ interface = "formula", protect = c("formula", "data"), func = c(fun = lm, pkg = "lm"), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -225,7 +225,7 @@ interface = "formula", protect = c("formula", "data"), func = c(fun = "stats", pkg = lm), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -235,7 +235,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = NULL)) Condition - Error in `check_fit_info()`: + Error in `set_fit()`: ! The `defaults` element should be a list: --- @@ -245,7 +245,7 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats"), defaults = list())) Condition - Error in `check_func_val()`: + Error in `set_fit()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. # set_fit() errors if engine doesn't match @@ -255,6 +255,6 @@ interface = "formula", protect = c("formula", "data"), func = c(pkg = "stats", fun = "lm"), defaults = list())) Condition - Error in `check_spec_mode_engine_val()`: + Error in `set_fit()`: ! Engine 'not stats' is not supported for `whale()`. See `show_engines('whale')`. diff --git a/tests/testthat/_snaps/set_model_arg.md b/tests/testthat/_snaps/set_model_arg.md index a7fe749..58f29f0 100644 --- a/tests/testthat/_snaps/set_model_arg.md +++ b/tests/testthat/_snaps/set_model_arg.md @@ -3,7 +3,7 @@ Code set_model_arg("light") Condition - Error in `check_model_val()`: + Error in `set_model_arg()`: ! Model `light` has not been registered. --- @@ -19,7 +19,7 @@ Code set_model_arg("thermos") Condition - Error in `check_eng_val()`: + Error in `set_model_arg()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -27,7 +27,7 @@ Code set_model_arg("thermos", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_model_arg()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -35,7 +35,7 @@ Code set_model_arg("thermos", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_arg()`: ! Please supply a character string for an engine name (e.g. `'stats'`). # set_model_arg() errors with wrong `exposed` argument @@ -43,7 +43,7 @@ Code set_model_arg(model = "marker", eng = "stats") Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. --- @@ -51,7 +51,7 @@ Code set_model_arg(model = "marker", eng = "stats", exposed = c("glmnet", "stats")) Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. --- @@ -59,7 +59,7 @@ Code set_model_arg(model = "marker", eng = "stats", exposed = NULL) Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. # set_model_arg() errors with wrong `original` argument @@ -67,7 +67,7 @@ Code set_model_arg(model = "mustache", eng = "stats", exposed = "method") Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. --- @@ -76,7 +76,7 @@ set_model_arg(model = "mustache", eng = "stats", exposed = "method", original = c( "not", "method")) Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. --- @@ -84,7 +84,7 @@ Code set_model_arg(model = "mustache", eng = "stats", exposed = "method", original = NULL) Condition - Error in `check_arg_val()`: + Error in `set_model_arg()`: ! Please supply a character string for the argument. # set_model_arg() errors with wrong `func` argument @@ -101,7 +101,7 @@ set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "method", func = c("not", "method")) Condition - Error in `check_func_val()`: + Error in `set_model_arg()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -110,7 +110,7 @@ set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "method", func = NULL) Condition - Error in `check_func_val()`: + Error in `set_model_arg()`: ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. # set_model_arg() errors with wrong `has_submodel` argument @@ -128,7 +128,7 @@ set_model_arg(model = "velcro", eng = "stats", exposed = "method", original = "method", func = list(pkg = "stats", fun = "lm"), has_submodel = "yes") Condition - Error in `check_submodels_val()`: + Error in `set_model_arg()`: ! The `submodels` argument should be a single logical. --- @@ -137,6 +137,6 @@ set_model_arg(model = "velcro", eng = "stats", exposed = "method", original = "method", func = list(pkg = "stats", fun = "lm"), has_submodel = NULL) Condition - Error in `check_submodels_val()`: + Error in `set_model_arg()`: ! The `submodels` argument should be a single logical. diff --git a/tests/testthat/_snaps/set_model_engine.md b/tests/testthat/_snaps/set_model_engine.md index 916ea1f..3cdf179 100644 --- a/tests/testthat/_snaps/set_model_engine.md +++ b/tests/testthat/_snaps/set_model_engine.md @@ -3,7 +3,7 @@ Code set_model_engine("panda", "partition", "stats") Condition - Error in `check_mode_for_new_engine()`: + Error in `set_model_engine()`: ! Engine 'stats' already exists for `panda()` with mode `partition`. # set_model_engine() errors with wrong `model` argument @@ -11,7 +11,7 @@ Code set_model_engine("stickynotes") Condition - Error in `check_model_val()`: + Error in `set_model_engine()`: ! Model `stickynotes` has not been registered. --- @@ -27,7 +27,7 @@ Code set_model_engine("paper") Condition - Error in `check_mode_val()`: + Error in `set_model_engine()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -35,7 +35,7 @@ Code set_model_engine("paper", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_model_engine()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -43,7 +43,7 @@ Code set_model_engine("paper", NULL) Condition - Error in `check_mode_val()`: + Error in `set_model_engine()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -51,7 +51,7 @@ Code set_model_engine("panda", "not partition", "stats") Condition - Error in `check_mode_for_new_engine()`: + Error in `set_model_engine()`: ! 'not partition' is not a known mode for model `panda()`. # set_model_engine() errors with wrong `engine` argument @@ -59,7 +59,7 @@ Code set_model_engine("street", "partition") Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -67,7 +67,7 @@ Code set_model_engine("street", "partition", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -75,6 +75,6 @@ Code set_model_engine("street", "partition", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). diff --git a/tests/testthat/_snaps/set_model_mode.md b/tests/testthat/_snaps/set_model_mode.md index 3b60bbb..b5c0ce1 100644 --- a/tests/testthat/_snaps/set_model_mode.md +++ b/tests/testthat/_snaps/set_model_mode.md @@ -3,7 +3,7 @@ Code set_model_mode("wagon") Condition - Error in `check_model_val()`: + Error in `set_model_mode()`: ! Model `wagon` has not been registered. --- @@ -19,7 +19,7 @@ Code set_model_mode("glass") Condition - Error in `check_mode_val()`: + Error in `set_model_mode()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -27,7 +27,7 @@ Code set_model_mode("glass", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_model_mode()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -35,6 +35,6 @@ Code set_model_mode("glass", NULL) Condition - Error in `check_mode_val()`: + Error in `set_model_mode()`: ! Please supply a character string for a mode (e.g. `'partition'`). diff --git a/tests/testthat/_snaps/set_pred.md b/tests/testthat/_snaps/set_pred.md index 7e92204..49c0396 100644 --- a/tests/testthat/_snaps/set_pred.md +++ b/tests/testthat/_snaps/set_pred.md @@ -3,7 +3,7 @@ Code set_pred("light") Condition - Error in `check_model_val()`: + Error in `set_pred()`: ! Model `light` has not been registered. --- @@ -21,7 +21,7 @@ Code set_pred("game") Condition - Error in `check_mode_val()`: + Error in `set_pred()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -29,7 +29,7 @@ Code set_pred("game", c("classification", "regression")) Condition - Error in `check_mode_val()`: + Error in `set_pred()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -37,7 +37,7 @@ Code set_pred("game", NULL) Condition - Error in `check_mode_val()`: + Error in `set_pred()`: ! Please supply a character string for a mode (e.g. `'partition'`). --- @@ -47,7 +47,7 @@ value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_spec_mode_engine_val()`: + Error in `set_pred()`: ! 'not partition' is not a known mode for model `game()`. # set_pred() errors with wrong `engine` argument @@ -55,7 +55,7 @@ Code set_pred("dog", "partition") Condition - Error in `check_eng_val()`: + Error in `set_pred()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -63,7 +63,7 @@ Code set_pred("dog", "partition", c("glmnet", "stats")) Condition - Error in `check_eng_val()`: + Error in `set_pred()`: ! Please supply a character string for an engine name (e.g. `'stats'`). --- @@ -71,7 +71,7 @@ Code set_model_engine("dog", "partition", NULL) Condition - Error in `check_eng_val()`: + Error in `set_model_engine()`: ! Please supply a character string for an engine name (e.g. `'stats'`). # set_pred() errors with wrong `value` argument @@ -87,7 +87,7 @@ Code set_pred("trunk", "partition", "stats", "raw", NULL) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -97,7 +97,7 @@ value = list(post = NULL, func = c(fun = "predict"), args = list(object = rlang::expr( object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -107,7 +107,7 @@ value = list(pre = NULL, func = c(fun = "predict"), args = list(object = rlang::expr( object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -117,7 +117,7 @@ value = list(pre = NULL, post = NULL, args = list(object = rlang::expr(object$ fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -126,7 +126,7 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `predict` module should have elements: `args`, `func`, `post`, `pre` --- @@ -136,7 +136,7 @@ value = list(pre = "NULL", post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `pre` module should be null or a function: --- @@ -146,7 +146,7 @@ value = list(pre = NULL, post = "NULL", func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `post` module should be null or a function: --- @@ -155,7 +155,7 @@ set_pred(model = "trunk", mode = "partition", eng = "stats", type = "raw", value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = "not a list")) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The `args` element should be a list. # set_pred() errors with wrong `type` argument @@ -165,7 +165,7 @@ value = list(pre = NULL, post = NULL, func = c(fun = "predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `check_pred_info()`: + Error in `set_pred()`: ! The prediction type should be one of: 'cluster', 'raw' # is_discordant_info() triggers for set_pred() @@ -175,6 +175,6 @@ value = list(pre = NULL, post = NULL, func = c(fun = "not predict"), args = list( object = rlang::expr(object$fit), newdata = rlang::expr(new_data), type = "response"))) Condition - Error in `is_discordant_info()`: + Error in `set_pred()`: ! The combination of engine 'stats' and mode 'partition' and prediction type 'raw' already has predict data for model 'diamond' and the new information being registered is different. From f4db3e7cbb24428579586b17fc29d9a3f050e277 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 11:04:34 -0800 Subject: [PATCH 5/9] document call argument --- DESCRIPTION | 2 +- R/check.R | 2 ++ man/check_spec_mode_engine_val.Rd | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe121f6..cb68826 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Description: An developer focused, low dependency package in 'tidymodels' that License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.2.3.9000 Imports: glue, rlang, diff --git a/R/check.R b/R/check.R index a9dfda5..1554348 100644 --- a/R/check.R +++ b/R/check.R @@ -81,6 +81,8 @@ check_eng_val <- function(eng, call = rlang::caller_env()) { #' @param mode Character of specific mode #' @param eng Character of specific engine #' +#' @inheritParams rlang::args_error_context +#' #' @return An error #' @examples #' library(rlang) diff --git a/man/check_spec_mode_engine_val.Rd b/man/check_spec_mode_engine_val.Rd index 4ee976a..937b319 100644 --- a/man/check_spec_mode_engine_val.Rd +++ b/man/check_spec_mode_engine_val.Rd @@ -4,7 +4,7 @@ \alias{check_spec_mode_engine_val} \title{Error handling for unknown mode} \usage{ -check_spec_mode_engine_val(model, mode, eng) +check_spec_mode_engine_val(model, mode, eng, call = rlang::caller_env()) } \arguments{ \item{model}{Character of specific model} @@ -12,6 +12,11 @@ check_spec_mode_engine_val(model, mode, eng) \item{mode}{Character of specific mode} \item{eng}{Character of specific engine} + +\item{call}{The execution environment of a currently +running function, e.g. \code{caller_env()}. The function will be +mentioned in error messages as the source of the error. See the +\code{call} argument of \code{\link[rlang:abort]{abort()}} for more information.} } \value{ An error From 08e1b5159cfd632ad744e8448920637784ec72f9 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 12:57:02 -0800 Subject: [PATCH 6/9] pass one more call --- R/set_pred.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/set_pred.R b/R/set_pred.R index 761d013..09d106a 100644 --- a/R/set_pred.R +++ b/R/set_pred.R @@ -137,7 +137,7 @@ check_pred_info <- function(pred_obj, type, call = rlang::caller_env()) { ) } - check_func_val(pred_obj$func) + check_func_val(pred_obj$func, call = call) if (!is.list(pred_obj$args)) { rlang::abort("The `args` element should be a list.", call = call) From 31a5427c57c7153575a4df6731199c732a3b052c Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 13:10:29 -0800 Subject: [PATCH 7/9] update GHA --- .github/workflows/R-CMD-check.yaml | 6 +----- .github/workflows/lock.yaml | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ee65ccb..ab1e0cb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -25,17 +25,13 @@ jobs: - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - # Use 3.6 to trigger usage of RTools35 - - {os: windows-latest, r: '3.6'} + # use 4.1 to check with rtools40's older compiler - {os: windows-latest, r: '4.1'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lock.yaml b/.github/workflows/lock.yaml index d55e238..3f63a3a 100644 --- a/.github/workflows/lock.yaml +++ b/.github/workflows/lock.yaml @@ -16,7 +16,7 @@ jobs: # issue-lock-labels: 'outdated' issue-lock-comment: > This issue has been automatically locked. If you believe you have - found a related problem, please file a new issue (with a reprex: + found a related problem, please file a new issue (with a reprex ) and link to this issue. issue-lock-reason: '' pr-lock-inactive-days: '14' @@ -24,7 +24,7 @@ jobs: pr-lock-labels: '' pr-lock-comment: > This pull request has been automatically locked. If you believe you - have found a related problem, please file a new issue (with a reprex: + have found a related problem, please file a new issue (with a reprex ) and link to this issue. pr-lock-reason: '' # process-only: 'issues' From 1f89483d367273ed5c1fd34d3ea2dbba8286814f Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 13:29:12 -0800 Subject: [PATCH 8/9] add is_missing(func) --- R/set_fit.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/set_fit.R b/R/set_fit.R index ebcb5d3..720d8e4 100644 --- a/R/set_fit.R +++ b/R/set_fit.R @@ -171,7 +171,7 @@ check_func_val <- function(func, call = rlang::caller_env()) { nms <- sort(names(func)) - if (all(is.null(nms))) { + if (rlang::is_missing(func) || all(is.null(nms))) { rlang::abort(msg, call = call) } From 5b995c8c3f022435a9dc4179256847f1566829ab Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 5 Jan 2024 13:39:00 -0800 Subject: [PATCH 9/9] make more errors robust to missing values --- R/set_fit.R | 6 +++--- R/set_model_arg.R | 4 +++- R/set_pred.R | 7 +++++++ tests/testthat/_snaps/set_model_arg.md | 4 ++-- tests/testthat/_snaps/set_pred.md | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/R/set_fit.R b/R/set_fit.R index 720d8e4..87f5bdc 100644 --- a/R/set_fit.R +++ b/R/set_fit.R @@ -169,12 +169,12 @@ check_func_val <- function(func, call = rlang::caller_env()) { "`func` and 'pkg' should both be single character strings." ) - nms <- sort(names(func)) - - if (rlang::is_missing(func) || all(is.null(nms))) { + if (rlang::is_missing(func) || all(is.null(sort(names(func))))) { rlang::abort(msg, call = call) } + nms <- sort(names(func)) + if (length(func) == 1) { if (isTRUE(any(nms != "fun"))) { rlang::abort(msg, call = call) diff --git a/R/set_model_arg.R b/R/set_model_arg.R index 0cc07ed..02002c9 100644 --- a/R/set_model_arg.R +++ b/R/set_model_arg.R @@ -87,7 +87,9 @@ check_arg_val <- function(arg, call = rlang::caller_env()) { } check_submodels_val <- function(has_submodel, call = rlang::caller_env()) { - if (!is.logical(has_submodel) || length(has_submodel) != 1) { + if (rlang::is_missing(has_submodel) || + !is.logical(has_submodel) || + length(has_submodel) != 1) { rlang::abort( "The `submodels` argument should be a single logical.", call = call diff --git a/R/set_pred.R b/R/set_pred.R index 09d106a..b5c1a29 100644 --- a/R/set_pred.R +++ b/R/set_pred.R @@ -103,6 +103,13 @@ get_pred_type <- function(model, type) { } check_pred_info <- function(pred_obj, type, call = rlang::caller_env()) { + if (rlang::is_missing(pred_obj)) { + rlang::abort( + "Argument `value` is missing, with no default.", + call = call + ) + } + if (all(type != pred_types)) { rlang::abort( glue::glue( diff --git a/tests/testthat/_snaps/set_model_arg.md b/tests/testthat/_snaps/set_model_arg.md index 58f29f0..a7f1193 100644 --- a/tests/testthat/_snaps/set_model_arg.md +++ b/tests/testthat/_snaps/set_model_arg.md @@ -93,7 +93,7 @@ set_model_arg(model = "unicorn", eng = "stats", exposed = "method", original = "moethod") Condition Error in `set_model_arg()`: - ! argument "func" is missing, with no default + ! `func` should be a named vector with element 'fun' and the optional elements 'pkg', 'range', 'trans', and 'values'. `func` and 'pkg' should both be single character strings. --- @@ -120,7 +120,7 @@ func = list(pkg = "stats", fun = "lm")) Condition Error in `set_model_arg()`: - ! argument "has_submodel" is missing, with no default + ! The `submodels` argument should be a single logical. --- diff --git a/tests/testthat/_snaps/set_pred.md b/tests/testthat/_snaps/set_pred.md index 49c0396..8aff86d 100644 --- a/tests/testthat/_snaps/set_pred.md +++ b/tests/testthat/_snaps/set_pred.md @@ -80,7 +80,7 @@ set_pred("trunk", "partition", "stats", "raw") Condition Error in `set_pred()`: - ! argument "value" is missing, with no default + ! Argument `value` is missing, with no default. ---