-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch to cli in various functions #1244
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6ef1f15
switch to cli in various functions
EmilHvitfeldt bc81909
update snapshot
EmilHvitfeldt 50f50a8
fix typo
EmilHvitfeldt a753fe0
add news
EmilHvitfeldt 74d7296
add snapshots to retraining tests
EmilHvitfeldt aa0dd02
add tests for check_training_set() errors
EmilHvitfeldt 62ede57
Update R/misc.R
EmilHvitfeldt c594a67
update snapshots
EmilHvitfeldt a4e3eb7
merge main
EmilHvitfeldt a102201
add another snapshot
EmilHvitfeldt File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ get_rhs_vars <- function(formula, data, no_lhs = FALSE) { | |
#' @export | ||
names0 <- function(num, prefix = "x") { | ||
if (num < 1) { | ||
rlang::abort("`num` should be > 0.") | ||
cli::cli_abort("{.arg num} should be > 0.") | ||
} | ||
ind <- format(seq_len(num)) | ||
ind <- gsub(" ", "0", ind) | ||
|
@@ -270,10 +270,11 @@ merge_term_info <- function(.new, .old) { | |
ellipse_check <- function(...) { | ||
terms <- quos(...) | ||
if (is_empty(terms)) { | ||
rlang::abort( | ||
paste0( | ||
"Please supply at least one variable specification.", | ||
"See ?selections." | ||
cli::cli_abort( | ||
c( | ||
"!" = "Please supply at least one variable specification.", | ||
"i" = "See {.help [?selections](recipes::selections)} \\ | ||
for more information." | ||
) | ||
) | ||
} | ||
|
@@ -325,10 +326,9 @@ printer <- function(tr_obj = NULL, | |
#' @keywords internal | ||
#' @rdname recipes-internal | ||
prepare <- function(x, ...) { | ||
rlang::abort(paste0( | ||
"As of version 0.0.1.9006, used `prep` ", | ||
"instead of `prepare`" | ||
)) | ||
cli::cli_abort( | ||
"As of version 0.0.1.9006 please use {.fn prep} instead of {.fn prepare}." | ||
) | ||
} | ||
|
||
|
||
|
@@ -607,30 +607,26 @@ check_nominal_type <- function(x, lvl) { | |
invisible(NULL) | ||
} | ||
|
||
check_training_set <- function(x, rec, fresh) { | ||
check_training_set <- function(x, rec, fresh, call = rlang::caller_env()) { | ||
# In case a variable has multiple roles | ||
vars <- unique(rec$var_info$variable) | ||
|
||
if (is.null(x)) { | ||
if (fresh) { | ||
rlang::abort( | ||
paste0( | ||
"A training set must be supplied to the `training` argument ", | ||
"when `fresh = TRUE`." | ||
) | ||
cli::cli_abort( | ||
"A training set must be supplied to the {.arg training} argument \\ | ||
when {.code fresh = TRUE}.", | ||
call = call | ||
) | ||
} | ||
x <- rec$template | ||
} else { | ||
in_data <- vars %in% colnames(x) | ||
if (!all(in_data)) { | ||
rlang::abort( | ||
paste0( | ||
"Not all variables in the recipe are present in the supplied ", | ||
"training set: ", | ||
paste0("'", vars[!in_data], "'", collapse = ", "), | ||
"." | ||
) | ||
cli::cli_abort( | ||
"Not all variables in the recipe are present in the supplied training \\ | ||
set: {.and {.var {vars[!in_data]}}}.", | ||
call = call | ||
) | ||
} | ||
if (!is_tibble(x)) { | ||
|
@@ -643,21 +639,20 @@ check_training_set <- function(x, rec, fresh) { | |
steps_trained <- vapply(rec$steps, is_trained, logical(1)) | ||
if (any(steps_trained) & !fresh) { | ||
if (!rec$retained) { | ||
rlang::abort( | ||
paste0( | ||
"To prep new steps after prepping the original ", | ||
"recipe, `retain = TRUE` must be set each time that ", | ||
"the recipe is trained." | ||
) | ||
cli::cli_abort( | ||
"To prep new steps after prepping the original recipe, \\ | ||
{.code retain = TRUE} must be set each time that the recipe is \\ | ||
trained.", | ||
call = call | ||
) | ||
} | ||
if (!is.null(rec$training)) { | ||
rlang::warn( | ||
paste0( | ||
"The previous data will be used by `prep`; ", | ||
"the data passed using `training` will be ", | ||
"ignored." | ||
) | ||
if (!is.null(rec$template)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the bug that is mentioned in the PR. |
||
cli::cli_warn( | ||
c( | ||
"!" = "The previous data will be used by {.fn prep}.", | ||
"i" = "the data passed using {.arg training} will be ignored." | ||
EmilHvitfeldt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
), | ||
call = call | ||
) | ||
} | ||
x <- rec$template | ||
|
@@ -779,11 +774,10 @@ dimred_data <- function(dat) { | |
uses_dim_red <- function(x) { | ||
dr <- inherits(x, "dimRedResult") | ||
if (dr) { | ||
rlang::abort( | ||
paste( | ||
"Recipes version >= 0.1.17 represents the estimates using a different format.", | ||
"Please recreate this recipe or use version 0.1.16 or less. See issue #823." | ||
) | ||
cli::cli_abort( | ||
"Recipes version >= 0.1.17 represents the estimates using a different \\ | ||
format. Please recreate this recipe or use version 0.1.16 or less. See \\ | ||
issue {.href [#823](https://github.com/tidymodels/recipes/issues/823)}." | ||
) | ||
} | ||
invisible(NULL) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# training in stages | ||
|
||
Code | ||
no_sulfur_trained <- prep(no_sulfur) | ||
Condition | ||
Warning in `prep()`: | ||
! The previous data will be used by `prep()`. | ||
i the data passed using `training` will be ignored. | ||
|
||
--- | ||
|
||
Code | ||
sequentially <- prep(scale_last) | ||
Condition | ||
Warning in `prep()`: | ||
! The previous data will be used by `prep()`. | ||
i the data passed using `training` will be ignored. | ||
|
||
--- | ||
|
||
Code | ||
in_stages_trained <- prep(in_stages) | ||
Condition | ||
Warning in `prep()`: | ||
! The previous data will be used by `prep()`. | ||
i the data passed using `training` will be ignored. | ||
|
||
--- | ||
|
||
Code | ||
rec %>% step_center(carbon, hydrogen, oxygen, nitrogen, sulfur) %>% prep( | ||
training = biomass) %>% step_rm(sulfur) %>% prep(training = biomass) | ||
Condition | ||
Warning in `prep()`: | ||
! The previous data will be used by `prep()`. | ||
i the data passed using `training` will be ignored. | ||
Message | ||
|
||
-- Recipe ---------------------------------------------------------------------- | ||
|
||
-- Inputs | ||
Number of variables by role | ||
outcome: 1 | ||
predictor: 5 | ||
|
||
-- Training information | ||
Training data contained 536 data points and no incomplete rows. | ||
|
||
-- Operations | ||
* Centering for: carbon, hydrogen, oxygen, nitrogen, sulfur | Trained | ||
* Variables removed: sulfur | Trained | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't add tests for this, as it is technically deprecated. I opened an issue to properly handle that here #1243