Skip to content

Commit 8bd7d4a

Browse files
committed
rebuild docs, checks pass
1 parent ef65227 commit 8bd7d4a

13 files changed

+242
-24
lines changed

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Depends:
1414
R (>= 3.5.0)
1515
Imports:
1616
assertthat,
17-
broom,
1817
cli,
1918
dplyr,
2019
epiprocess,

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export(knn_iteraive_ar_args_list)
4040
export(knn_iteraive_ar_forecaster)
4141
export(knnarx_args_list)
4242
export(knnarx_forecaster)
43+
export(layer_naomit)
44+
export(layer_predict)
45+
export(slather)
4346
export(smooth_arx_args_list)
4447
export(smooth_arx_forecaster)
4548
export(step_epi_ahead)

R/epi_recipe.R

+2-15
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ epi_recipe.default <- function(x, ...) {
2323
}
2424

2525
#' @rdname epi_recipe
26-
#' @param vars A character string of column names corresponding to variables
27-
#' that will be used in any context (see below)
26+
#' @inheritParams recipes::recipe
2827
#' @param roles A character string (the same length of `vars`) that
2928
#' describes a single role that the variable will take. This value could be
3029
#' anything but common roles are `"outcome"`, `"predictor"`,
@@ -38,19 +37,7 @@ epi_recipe.default <- function(x, ...) {
3837
#' `cbind`; see Examples).
3938
#' @param x,data A data frame, tibble, or epi_df of the *template* data set
4039
#' (see below). This is always coerced to the first row to avoid memory issues
41-
#' @return An object of class `recipe` with sub-objects:
42-
#' \item{var_info}{A tibble containing information about the original data
43-
#' set columns}
44-
#' \item{term_info}{A tibble that contains the current set of terms in the
45-
#' data set. This initially defaults to the same data contained in
46-
#' `var_info`.}
47-
#' \item{steps}{A list of `step` or `check` objects that define the sequence of
48-
#' preprocessing operations that will be applied to data. The default value is
49-
#' `NULL`}
50-
#' \item{template}{A tibble of the data. This is initialized to be the same
51-
#' as the data given in the `data` argument but can be different after
52-
#' the recipe is trained.}
53-
#'
40+
#' @inherit recipes::recipe return
5441
#'
5542
#' @export
5643
#' @examples

R/epi_workflow.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#' and numerous examples, see there.
1010
#'
1111
#' @inheritParams workflows::workflow
12+
#' @param postprocessor An optional postprocessor to add to the workflow.
13+
#' Currently only `frosting` is allowed using, `add_frosting()`.
1214
#'
1315
#' @return A new `epi_workflow` object.
1416
#' @seealso workflows::workflow
@@ -81,7 +83,6 @@ is_epi_workflow <- function(x) {
8183
#' `geo_value` columns as well as the prediction.
8284
#'
8385
#' @inheritParams parsnip::predict.model_fit
84-
#' @param forecast_date The date on which the forecast is (was) made.
8586
#'
8687
#' @param object An epi_workflow that has been fit by
8788
#' [workflows::fit.workflow()]
@@ -113,7 +114,7 @@ is_epi_workflow <- function(x) {
113114
#'
114115
#' wf <- epi_workflow(r, linear_reg()) %>% fit(jhu)
115116
#'
116-
#' latest <- get_test_data(r, jhu)
117+
#' latest <- jhu %>% filter(time_value >= max(time_value) - 14)
117118
#'
118119
#' preds <- predict(wf, latest) %>%
119120
#' filter(!is.na(.pred))

R/frosting.R

+38-1
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,22 @@ frosting <- function(layers = NULL, requirements = NULL) {
5858
out <- new_frosting()
5959
}
6060

61+
#' Apply postprocessing to a fitted workflow
62+
#'
63+
#' This function is intended for internal use. It implements postprocessing
64+
#' inside of the `predict()` method for a fitted workflow.
65+
#'
66+
#' @param workflow An object of class workflow
67+
#' @param ... additional arguments passed on to methods
68+
#'
69+
#' @aliases apply_frosting.default apply_frosting.epi_recipe
6170
#' @export
6271
apply_frosting <- function(workflow, ...) {
6372
UseMethod("apply_frosting")
6473
}
6574

75+
#' @inheritParams slather
76+
#' @rdname apply_frosting
6677
#' @export
6778
apply_frosting.default <- function(workflow, components, ...) {
6879
if (has_postprocessor(workflow)) {
@@ -74,6 +85,7 @@ apply_frosting.default <- function(workflow, components, ...) {
7485

7586

7687

88+
#' @rdname apply_frosting
7789
#' @importFrom rlang is_null
7890
#' @importFrom rlang abort
7991
#' @export
@@ -113,7 +125,32 @@ add_layer <- function(frosting, object) {
113125
frosting
114126
}
115127

116-
slather <- function(x, ...) {
128+
129+
#' Spread a layer of frosting on a fitted workflow
130+
#'
131+
#' Slathering frosting means to implement a postprocessing layer. When
132+
#' creating a new postprocessing layer, you must implement an S3 method
133+
#' for this function
134+
#'
135+
#' @param object a workflow with `frosting` postprocessing steps
136+
#' @param components a list of components containing model information. These
137+
#' will be updated and returned by the layer. These should be
138+
#' * `mold` - the output of calling `hardhat::mold()` on the workflow. This
139+
#' contains information about the preprocessing, including the recipe.
140+
#' * `forged` - the output of calling `hardhat::forge()` on the workflow.
141+
#' This should have predictors and outcomes for the `new_data`. It will
142+
#' have three components `predictors`, `outcomes` (if these were in the
143+
#' `new_data`), and `extras` (usually has the rest of the data, including
144+
#' `keys`).
145+
#' * `keys` - we put the keys (`time_value`, `geo_value`, and any others)
146+
#' here for ease.
147+
#' @param the_fit the fitted model object as returned by calling `parsnip::fit()`
148+
#'
149+
#' @param ... additional arguments used by methods. Currently unused.
150+
#'
151+
#' @return The `components` list. In the same format after applying any updates.
152+
#' @export
153+
slather <- function(object, components, the_fit, ...) {
117154
UseMethod("slather")
118155
}
119156

R/layer_naomit.R

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
#' Omit `NA`s from predictions or other columns
2+
#'
3+
#' @param frosting a `frosting` postprocessor
4+
#' @param ... <[`tidy-select`][dplyr::dplyr_tidy_select]> One or more unquoted
5+
#' expressions separated by commas. Variable names can be used as if they
6+
#' were positions in the data frame, so expressions like `x:y` can
7+
#' be used to select a range of variables. Typical usage is `.pred` to remove
8+
#' any rows with `NA` predictions.
9+
#' @param id a random id string
10+
#'
11+
#' @return an updated `frosting` postprocessor
12+
#' @export
113
layer_naomit <- function(frosting, ..., id = rand_id("naomit")) {
214
add_layer(
315
frosting,
@@ -13,7 +25,7 @@ layer_naomit_new <- function(terms, id) {
1325
}
1426

1527
#' @export
16-
slather.layer_naomit <- function(object, components, the_fit) {
28+
slather.layer_naomit <- function(object, components, the_fit,...) {
1729
exprs <- rlang::expr(c(!!!object$terms))
1830
pos <- tidyselect::eval_select(exprs, components$predictions)
1931
col_names <- names(pos)

R/layer_predict.R

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
#' Prediction layer for postprocessing
2+
#'
3+
#' Implements prediction on a fitted `epi_workflow`. One may want different
4+
#' types of prediction, and to potentially apply this after some amount of
5+
#' postprocessing. This would typically be the first layer in a `frosting`
6+
#' postprocessor.
7+
#'
8+
#' @seealso `parsnip::predict.model_fit()`
9+
#'
10+
#' @inheritParams parsnip::predict.model_fit
11+
#' @param frosting a frosting object
12+
#' @param id a string identifying the layer
13+
#'
14+
#' @return An updated `frosting` object
15+
#' @export
116
layer_predict <-
217
function(frosting, type = NULL, opts = list(), ..., id = rand_id("predict_default")) {
318
add_layer(
@@ -17,7 +32,7 @@ layer_predict_new <- function(type, opts, dots_list, id) {
1732
}
1833

1934
#' @export
20-
slather.layer_predict <- function(object, components, the_fit) {
35+
slather.layer_predict <- function(object, components, the_fit, ...) {
2136

2237
components$predictions <- predict(the_fit, components$forged$predictors,
2338
type = object$type, opts = object$opts)

man/apply_frosting.Rd

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_workflow.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/layer_naomit.Rd

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/layer_predict.Rd

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/predict-epi_workflow.Rd

+1-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/slather.Rd

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)