Skip to content

Commit 682dbdd

Browse files
committed
add in simple examples
1 parent 8493d0f commit 682dbdd

File tree

6 files changed

+148
-11
lines changed

6 files changed

+148
-11
lines changed

R/epi_recipe.R

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ epi_recipe.default <- function(x, ...) {
5454
# @includeRmd man/rmd/recipes.Rmd details
5555
#'
5656
#' @export
57+
#' @examples
58+
#' library(epiprocess)
59+
#' library(dplyr)
60+
#' jhu <- jhu_csse_daily_subset %>%
61+
#' filter(time_value > "2021-08-01") %>%
62+
#' select(geo_value:death_rate_7d_av) %>%
63+
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
64+
#'
65+
#' r <- epi_recipe(x) %>%
66+
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
67+
#' step_epi_ahead(death_rate, ahead = 7) %>%
68+
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
69+
#' step_naomit(all_predictors()) %>%
70+
#' # below, `skip` means we don't do this at predict time
71+
#' step_naomit(all_outcomes(), skip = TRUE)
72+
#'
73+
#' r
5774
epi_recipe.epi_df <-
5875
function(x,
5976
formula = NULL,
@@ -254,16 +271,24 @@ is_epi_recipe <- function(x) {
254271
#'
255272
#' @export
256273
#' @examples
257-
#' library(magrittr)
274+
#' library(epiprocess)
275+
#' library(dplyr)
276+
#' jhu <- jhu_csse_daily_subset %>%
277+
#' filter(time_value > "2021-08-01") %>%
278+
#' select(geo_value:death_rate_7d_av) %>%
279+
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
258280
#'
259-
#' recipe <- epi_recipe(mpg ~ cyl, mtcars) %>%
260-
#' step_log(cyl)
281+
#' r <- epi_recipe(x) %>%
282+
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
283+
#' step_epi_ahead(death_rate, ahead = 7) %>%
284+
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
285+
#' step_naomit(all_predictors()) %>%
286+
#' step_naomit(all_outcomes(), skip = TRUE)
261287
#'
262288
#' workflow <- epi_workflow() %>%
263-
#' add_epi_recipe(recipe)
289+
#' add_epi_recipe(r)
264290
#'
265291
#' workflow
266-
#'
267292
add_epi_recipe <- function(
268293
x, recipe, ..., blueprint = default_epi_recipe_blueprint()) {
269294
add_recipe(x, recipe, ..., blueprint = blueprint)

R/epi_workflow.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
#' @seealso workflows::workflow
1515
#' @importFrom rlang is_null
1616
#' @export
17+
#' @examples
18+
#' library(epiprocess)
19+
#' library(dplyr)
20+
#' library(parsnip)
21+
#'
22+
#' jhu <- jhu_csse_daily_subset %>%
23+
#' filter(time_value > "2021-08-01") %>%
24+
#' select(geo_value:death_rate_7d_av) %>%
25+
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
26+
#'
27+
#' r <- epi_recipe(x) %>%
28+
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
29+
#' step_epi_ahead(death_rate, ahead = 7) %>%
30+
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
31+
#' step_naomit(all_predictors()) %>%
32+
#' step_naomit(all_outcomes(), skip = TRUE)
33+
#'
34+
#' wf <- epi_workflow(r, linear_reg())
35+
#'
36+
#' wf
1737
epi_workflow <- function(preprocessor = NULL, spec = NULL) {
1838
out <- workflows::workflow(spec = spec)
1939
class(out) <- c("epi_workflow", class(out))
@@ -71,6 +91,28 @@ is_epi_workflow <- function(x) {
7191
#'
7292
#' @name predict-epi_workflow
7393
#' @export
94+
#' @examples
95+
#'
96+
#' #' library(epiprocess)
97+
#' library(dplyr)
98+
#' library(parsnip)
99+
#'
100+
#' jhu <- jhu_csse_daily_subset %>%
101+
#' filter(time_value > "2021-08-01") %>%
102+
#' select(geo_value:death_rate_7d_av) %>%
103+
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
104+
#'
105+
#' r <- epi_recipe(x) %>%
106+
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
107+
#' step_epi_ahead(death_rate, ahead = 7) %>%
108+
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
109+
#' step_naomit(all_predictors()) %>%
110+
#' step_naomit(all_outcomes(), skip = TRUE)
111+
#'
112+
#' wf <- epi_workflow(r, linear_reg())
113+
#' preds <- predict(wf, forecast_date = "2021-12-31")
114+
#'
115+
#' preds
74116
predict.epi_workflow <-
75117
function(object, new_data, type = NULL, opts = list(),
76118
forecast_date = NULL, ...) {

man/add_epi_recipe.Rd

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_recipe.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_workflow.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/predict-epi_workflow.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)