Skip to content

Commit

Permalink
Merge branch 'dev' into ndefries/epidatasets-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nmdefries committed Oct 1, 2024
2 parents bf9c101 + 37f3ad0 commit e210607
Show file tree
Hide file tree
Showing 22 changed files with 1,544 additions and 1,234 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: epipredict
Title: Basic epidemiology forecasting methods
Version: 0.0.21
Version: 0.0.24
Authors@R: c(
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")),
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -38,7 +38,7 @@ Imports:
hardhat (>= 1.3.0),
magrittr,
recipes (>= 1.0.4),
rlang (>= 1.0.0),
rlang (>= 1.1.0),
stats,
tibble,
tidyr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ importFrom(rlang,":=")
importFrom(rlang,abort)
importFrom(rlang,arg_match)
importFrom(rlang,as_function)
importFrom(rlang,caller_arg)
importFrom(rlang,caller_env)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
- Add `step_epi_slide` to produce generic sliding computations over an `epi_df`
- Add quantile random forests (via `{grf}`) as a parsnip engine
- Replace `epi_keys()` with `epiprocess::key_colnames()`, #352
- More descriptive error messages from `arg_is_*()`, #287
- Fix bug where `fit()` drops the `epi_workflow` class (also error if
non-`epi_df` data is given to `epi_recipe()`), #363
- Try to retain the `epi_df` class during baking to the extent possible, #376
26 changes: 11 additions & 15 deletions R/epi_recipe.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ epi_recipe <- function(x, ...) {
#' @rdname epi_recipe
#' @export
epi_recipe.default <- function(x, ...) {
## if not a formula or an epi_df, we just pass to recipes::recipe
if (is.matrix(x) || is.data.frame(x) || tibble::is_tibble(x)) {
x <- x[1, , drop = FALSE]
}
cli_warn(
"epi_recipe has been called with a non-epi_df object, returning a regular recipe. Various
step_epi_* functions will not work."
)
recipes::recipe(x, ...)
cli_abort(paste(
"`x` must be an {.cls epi_df} or a {.cls formula},",
"not a {.cls {class(x)[[1]]}}."
))
}

#' @rdname epi_recipe
Expand Down Expand Up @@ -63,6 +58,7 @@ epi_recipe.default <- function(x, ...) {
#' r
epi_recipe.epi_df <-
function(x, formula = NULL, ..., vars = NULL, roles = NULL) {
attr(x, "decay_to_tibble") <- FALSE
if (!is.null(formula)) {
if (!is.null(vars)) {
rlang::abort(
Expand Down Expand Up @@ -153,16 +149,16 @@ epi_recipe.formula <- function(formula, data, ...) {
data <- data[1, ]
# check for minus:
if (!epiprocess::is_epi_df(data)) {
cli_warn(
"epi_recipe has been called with a non-epi_df object, returning a regular recipe. Various
step_epi_* functions will not work."
)
return(recipes::recipe(formula, data, ...))
cli_abort(paste(
"`epi_recipe()` has been called with a non-{.cls epi_df} object.",
"Use `recipe()` instead."
))
}

attr(data, "decay_to_tibble") <- FALSE
f_funcs <- recipes:::fun_calls(formula, data)
if (any(f_funcs == "-")) {
abort("`-` is not allowed in a recipe formula. Use `step_rm()` instead.")
cli_abort("`-` is not allowed in a recipe formula. Use `step_rm()` instead.")
}

# Check for other in-line functions
Expand Down
4 changes: 3 additions & 1 deletion R/epi_workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ fit.epi_workflow <- function(object, data, ..., control = workflows::control_wor
)
object$original_data <- data

NextMethod()
res <- NextMethod()
class(res) <- c("epi_workflow", class(res))
res
}

#' Predict from an epi_workflow
Expand Down
24 changes: 13 additions & 11 deletions R/epipredict-package.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## usethis namespace: start
#' @importFrom tibble as_tibble
#' @importFrom rlang := !! %||% as_function global_env set_names !!!
#' is_logical is_true inject enquo enquos expr sym arg_match
#' @importFrom stats poly predict lm residuals quantile
#' @importFrom dplyr arrange across all_of any_of bind_cols bind_rows group_by
#' summarize filter mutate select left_join rename ungroup full_join
#' relocate summarise everything
#' @importFrom cli cli_abort cli_warn
#' @importFrom checkmate assert assert_character assert_int assert_scalar
#' assert_logical assert_numeric assert_number assert_integer
#' assert_integerish assert_date assert_function assert_class
#' @import epiprocess parsnip epidatasets
#' @importFrom checkmate assert assert_character assert_int assert_scalar
#' @importFrom checkmate assert_logical assert_numeric assert_number
#' @importFrom checkmate assert_integer assert_integerish
#' @importFrom checkmate assert_date assert_function assert_class
#' @importFrom cli cli_abort cli_warn
#' @importFrom dplyr arrange across all_of any_of bind_cols bind_rows group_by
#' @importFrom dplyr summarize filter mutate select left_join rename ungroup
#' @importFrom dplyr full_join relocate summarise everything
#' @importFrom rlang := !! %||% as_function global_env set_names !!! caller_arg
#' @importFrom rlang is_logical is_true inject enquo enquos expr sym arg_match
#' @importFrom stats poly predict lm residuals quantile
#' @importFrom tibble as_tibble
na_chr <- NA_character_
## usethis namespace: end
NULL
Loading

0 comments on commit e210607

Please sign in to comment.