Skip to content

Commit d8c99c9

Browse files
committed
examples build, bump R dependencies
1 parent 4c4401e commit d8c99c9

File tree

7 files changed

+56
-23
lines changed

7 files changed

+56
-23
lines changed

DESCRIPTION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,32 @@ Description: What the package does (one paragraph).
1010
License: MIT + file LICENSE
1111
URL: https://github.com/cmu-delphi/epipredict/,
1212
https://cmu-delphi.github.io/epiprocess
13+
Depends:
14+
R (>= 3.5.0)
1315
Imports:
1416
assertthat,
1517
cli,
1618
dplyr,
19+
epiprocess,
1720
glue,
21+
hardhat (>= 1.0.0.9000),
1822
magrittr,
1923
purrr,
2024
recipes (>= 0.2.0.9001),
2125
rlang,
2226
stats,
27+
tensr,
2328
tibble,
2429
tidyr,
2530
tidyselect,
26-
tensr,
27-
hardhat (>= 1.0.0.9000)
31+
workflows
2832
Suggests:
2933
covidcast,
3034
data.table,
31-
epiprocess,
3235
ggplot2,
3336
knitr,
3437
lubridate,
38+
parsnip (>= 0.2.1.9001),
3539
RcppRoll,
3640
rmarkdown,
3741
testthat (>= 3.0.0)

R/epi_recipe.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' A recipe is a description of the steps to be applied to a data set in
44
#' order to prepare it for data analysis. This is a loose wrapper
5-
#' around `recipes::recipe()` to properly handle the additional
5+
#' around [recipes::recipe()] to properly handle the additional
66
#' columns present in an `epi_df`
77
#'
88
#' @aliases epi_recipe epi_recipe.default epi_recipe.formula
@@ -51,18 +51,19 @@ epi_recipe.default <- function(x, ...) {
5151
#' as the data given in the `data` argument but can be different after
5252
#' the recipe is trained.}
5353
#'
54-
# @includeRmd man/rmd/recipes.Rmd details
5554
#'
5655
#' @export
5756
#' @examples
5857
#' library(epiprocess)
5958
#' library(dplyr)
59+
#' library(recipes)
60+
#'
6061
#' jhu <- jhu_csse_daily_subset %>%
6162
#' filter(time_value > "2021-08-01") %>%
6263
#' select(geo_value:death_rate_7d_av) %>%
6364
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
6465
#'
65-
#' r <- epi_recipe(x) %>%
66+
#' r <- epi_recipe(jhu) %>%
6667
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
6768
#' step_epi_ahead(death_rate, ahead = 7) %>%
6869
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
@@ -273,12 +274,14 @@ is_epi_recipe <- function(x) {
273274
#' @examples
274275
#' library(epiprocess)
275276
#' library(dplyr)
277+
#' library(recipes)
278+
#'
276279
#' jhu <- jhu_csse_daily_subset %>%
277280
#' filter(time_value > "2021-08-01") %>%
278281
#' select(geo_value:death_rate_7d_av) %>%
279282
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
280283
#'
281-
#' r <- epi_recipe(x) %>%
284+
#' r <- epi_recipe(jhu) %>%
282285
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
283286
#' step_epi_ahead(death_rate, ahead = 7) %>%
284287
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
@@ -291,7 +294,7 @@ is_epi_recipe <- function(x) {
291294
#' workflow
292295
add_epi_recipe <- function(
293296
x, recipe, ..., blueprint = default_epi_recipe_blueprint()) {
294-
add_recipe(x, recipe, ..., blueprint = blueprint)
297+
workflows::add_recipe(x, recipe, ..., blueprint = blueprint)
295298
}
296299

297300

R/epi_workflow.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#'
33
#' This is a container object that unifies preprocessing, fitting, prediction,
44
#' and postprocessing for predictive modeling on epidemiological data. It extends
5-
#' the functionality of a [`workflows::workflow()`] to handle the typical panel
5+
#' the functionality of a [workflows::workflow()] to handle the typical panel
66
#' data structures found in this field. This extension is handled completely
77
#' internally, and should be invisible to the user. For all intents and purposes,
8-
#' this operates exactly like a [`workflows::workflow()`]. For more details
8+
#' this operates exactly like a [workflows::workflow()]. For more details
99
#' and numerous examples, see there.
1010
#'
1111
#' @inheritParams workflows::workflow
@@ -18,13 +18,14 @@
1818
#' library(epiprocess)
1919
#' library(dplyr)
2020
#' library(parsnip)
21+
#' library(recipes)
2122
#'
2223
#' jhu <- jhu_csse_daily_subset %>%
2324
#' filter(time_value > "2021-08-01") %>%
2425
#' select(geo_value:death_rate_7d_av) %>%
2526
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
2627
#'
27-
#' r <- epi_recipe(x) %>%
28+
#' r <- epi_recipe(jhu) %>%
2829
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
2930
#' step_epi_ahead(death_rate, ahead = 7) %>%
3031
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
@@ -79,7 +80,8 @@ is_epi_workflow <- function(x) {
7980
#' @inheritParams parsnip::predict.model_fit
8081
#' @param forecast_date The date on which the forecast is (was) made.
8182
#'
82-
#' @param object An epi_workflow that has been fit by [fit.workflow()]
83+
#' @param object An epi_workflow that has been fit by
84+
#' [workflows::fit.workflow()]
8385
#'
8486
#' @param new_data A data frame containing the new predictors to preprocess
8587
#' and predict on
@@ -96,21 +98,30 @@ is_epi_workflow <- function(x) {
9698
#' library(epiprocess)
9799
#' library(dplyr)
98100
#' library(parsnip)
101+
#' library(recipes)
99102
#'
100103
#' jhu <- jhu_csse_daily_subset %>%
101104
#' filter(time_value > "2021-08-01") %>%
102105
#' select(geo_value:death_rate_7d_av) %>%
103106
#' rename(case_rate = case_rate_7d_av, death_rate = death_rate_7d_av)
104107
#'
105-
#' r <- epi_recipe(x) %>%
108+
#' r <- epi_recipe(jhu) %>%
106109
#' step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
107110
#' step_epi_ahead(death_rate, ahead = 7) %>%
108111
#' step_epi_lag(case_rate, lag = c(0, 7, 14)) %>%
109112
#' step_naomit(all_predictors()) %>%
110113
#' step_naomit(all_outcomes(), skip = TRUE)
111114
#'
112-
#' wf <- epi_workflow(r, linear_reg())
113-
#' preds <- predict(wf, forecast_date = "2021-12-31")
115+
#' wf <- epi_workflow(r, linear_reg()) %>% fit(jhu)
116+
#'
117+
#' jhu_latest <- jhu %>%
118+
#' filter(!is.na(case_rate), !is.na(death_rate)) %>%
119+
#' group_by(geo_value) %>%
120+
#' slice_tail(n = 15) %>% # have lags 0,...,14, so need 15 for a complete case
121+
#' ungroup()
122+
#'
123+
#' preds <- predict(wf, jhu_latest, forecast_date = "2021-12-31") %>%
124+
#' filter(!is.na(.pred))
114125
#'
115126
#' preds
116127
predict.epi_workflow <-

man/add_epi_recipe.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_recipe.Rd

Lines changed: 4 additions & 2 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: 2 additions & 1 deletion
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: 14 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)