Skip to content

Commit 378577a

Browse files
authored
Merge pull request #258 from cmu-delphi/djm/update-mods
Djm/update mods
2 parents 61a4076 + c1234f7 commit 378577a

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

R/epi_recipe.R

+12-8
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,23 @@ adjust_epi_recipe.epi_recipe <- function(
404404
x$steps[[which_step]] <- update(x$steps[[which_step]], ...)
405405
} else {
406406
step_names <- map_chr(x$steps, ~ attr(.x, "class")[1])
407+
starts_with_step <- substr(which_step, 1, 5) == "step_"
408+
if (!starts_with_step) which_step <- paste0("step_", which_step)
407409

408410
if (!(which_step %in% step_names)) {
409-
cli::cli_abort(
410-
c("`which_step` is not in the `epi_recipe` step names. ",
411-
"i" = "The step names are {step_names}."
412-
)
413-
)
411+
cli::cli_abort(c(
412+
"`which_step` does not appear in the available `epi_recipe` step names. ",
413+
i = "The step names are {.val {step_names}}."
414+
))
414415
}
415416
which_step_idx <- which(step_names == which_step)
416417
if (length(which_step_idx) == 1) {
417418
x$steps[[which_step_idx]] <- update(x$steps[[which_step_idx]], ...)
418419
} else {
419-
cli::cli_abort("`which_step` is not unique. Matches steps: {which_step_idx}.")
420+
cli::cli_abort(c(
421+
"`which_step` is not unique. Matches steps: {.val {which_step_idx}}.",
422+
i = "Please use the step number instead for precise alterations."
423+
))
420424
}
421425
}
422426
x
@@ -444,7 +448,7 @@ prep.epi_recipe <- function(
444448
}
445449
skippers <- map_lgl(x$steps, recipes:::is_skipable)
446450
if (any(skippers) & !retain) {
447-
rlang::warn(c(
451+
cli::cli_warn(c(
448452
"Since some operations have `skip = TRUE`, using ",
449453
"`retain = TRUE` will allow those steps results to ",
450454
"be accessible."
@@ -477,7 +481,7 @@ prep.epi_recipe <- function(
477481
)
478482
training <- bake(x$steps[[i]], new_data = training)
479483
if (!tibble::is_tibble(training)) {
480-
abort("bake() methods should always return tibbles")
484+
cli::cli_abort("`bake()` methods should always return {.cls tibble}.")
481485
}
482486
if (!is_epi_df(training)) {
483487
# tidymodels killed our class

R/frosting.R

+22-17
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,23 @@ adjust_frosting.frosting <- function(
186186
x$layers[[which_layer]] <- update(x$layers[[which_layer]], ...)
187187
} else {
188188
layer_names <- map_chr(x$layers, ~ attr(.x, "class")[1])
189+
starts_with_layer <- substr(which_layer, 1, 6) == "layer_"
190+
if (!starts_with_layer) which_layer <- paste0("layer_", which_layer)
189191

190192
if (!(which_layer %in% layer_names)) {
191-
cli::cli_abort(
192-
c("`which_layer` is not in the `frosting` layer names. ",
193-
"i" = "The layer names are {layer_names}."
194-
)
195-
)
193+
cli::cli_abort(c(
194+
"`which_layer` does not appear in the available `frosting` layer names. ",
195+
i = "The layer names are {.val {layer_names}}."
196+
))
196197
}
197198
which_layer_idx <- which(layer_names == which_layer)
198199
if (length(which_layer_idx) == 1) {
199200
x$layers[[which_layer_idx]] <- update(x$layers[[which_layer_idx]], ...)
200201
} else {
201-
cli::cli_abort("`which_layer` is not unique. Matches layers: {which_layer_idx}.")
202+
cli::cli_abort(c(
203+
"`which_layer` is not unique. Matches layers: {.val {which_layer_idx}}.",
204+
i = "Please use the layer number instead for precise alterations."
205+
))
202206
}
203207
}
204208
x
@@ -212,7 +216,7 @@ add_postprocessor <- function(x, postprocessor, ..., call = caller_env()) {
212216
if (is_frosting(postprocessor)) {
213217
return(add_frosting(x, postprocessor))
214218
}
215-
rlang::abort("`postprocessor` must be a frosting object.", call = call)
219+
cli::cli_abort("`postprocessor` must be a frosting object.", call = call)
216220
}
217221

218222
is_frosting <- function(x) {
@@ -223,8 +227,8 @@ is_frosting <- function(x) {
223227
validate_frosting <- function(x, ..., arg = "`x`", call = caller_env()) {
224228
rlang::check_dots_empty()
225229
if (!is_frosting(x)) {
226-
glubort(
227-
"{arg} must be a frosting postprocessor, not a {class(x)[[1]]}.",
230+
cli::cli_abort(
231+
"{arg} must be a frosting postprocessor, not a {.cls {class(x)[[1]]}}.",
228232
.call = call
229233
)
230234
}
@@ -283,10 +287,9 @@ new_frosting <- function() {
283287
#' p
284288
frosting <- function(layers = NULL, requirements = NULL) {
285289
if (!is_null(layers) || !is_null(requirements)) {
286-
rlang::abort(c(
287-
"Currently, no arguments to `frosting()` are allowed",
288-
"to be non-null."
289-
))
290+
cli::cli_abort(
291+
"Currently, no arguments to `frosting()` are allowed to be non-null."
292+
)
290293
}
291294
out <- new_frosting()
292295
}
@@ -305,7 +308,8 @@ extract_frosting <- function(x, ...) {
305308

306309
#' @export
307310
extract_frosting.default <- function(x, ...) {
308-
abort(c("Frosting is only available for epi_workflows currently.",
311+
cli::cli_abort(c(
312+
"Frosting is only available for epi_workflows currently.",
309313
i = "Can you use `epi_workflow()` instead of `workflow()`?"
310314
))
311315
invisible(x)
@@ -339,7 +343,8 @@ apply_frosting <- function(workflow, ...) {
339343
#' @export
340344
apply_frosting.default <- function(workflow, components, ...) {
341345
if (has_postprocessor(workflow)) {
342-
abort(c("Postprocessing is only available for epi_workflows currently.",
346+
cli::cli_abort(c(
347+
"Postprocessing is only available for epi_workflows currently.",
343348
i = "Can you use `epi_workflow()` instead of `workflow()`?"
344349
))
345350
}
@@ -367,8 +372,8 @@ apply_frosting.epi_workflow <-
367372
}
368373

369374
if (!has_postprocessor_frosting(workflow)) {
370-
rlang::warn(c(
371-
"Only postprocessors of class frosting are allowed.",
375+
cli::cli_warn(c(
376+
"Only postprocessors of class {.cls frosting} are allowed.",
372377
"Returning unpostprocessed predictions."
373378
))
374379
components$predictions <- predict(

R/tidy.R

+2-6
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,9 @@ tidy.frosting <- function(x, number = NA, id = NA, ...) {
103103
res
104104
}
105105

106-
#' @rdname tidy.layer
107106
#' @export
108107
tidy.layer <- function(x, ...) {
109-
rlang::abort(
110-
paste0(
111-
"No `tidy` method for a layer with classes: ",
112-
paste0(class(x), collapse = ", ")
113-
)
108+
cli::cli_abort(
109+
"No `tidy()` method exists for a layer with class: {.cls {class(x)}}."
114110
)
115111
}

_pkgdown.yml

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ reference:
4848
- epi_recipe
4949
- epi_workflow
5050
- add_epi_recipe
51+
- adjust_epi_recipe
52+
- add_model
5153
- predict.epi_workflow
5254
- fit.epi_workflow
5355
- augment.epi_workflow
@@ -62,6 +64,7 @@ reference:
6264
- frosting
6365
- ends_with("_frosting")
6466
- get_test_data
67+
- tidy.frosting
6568
- title: Frosting layers
6669
contents:
6770
- contains("layer")

add_model.Rd

Whitespace-only changes.

0 commit comments

Comments
 (0)