Skip to content

Commit

Permalink
Merge pull request #331 from cmu-delphi/djm/deprecate
Browse files Browse the repository at this point in the history
Djm/deprecate
  • Loading branch information
dajmcdon authored May 13, 2024
2 parents 5aa7828 + f9c1f8f commit de6e1db
Show file tree
Hide file tree
Showing 19 changed files with 318 additions and 306 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.14
Version: 0.0.15
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:
magrittr,
quantreg,
recipes (>= 1.0.4),
rlang,
rlang (>= 1.0.0),
smoothqr,
stats,
tibble,
Expand Down
7 changes: 3 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,11 @@ importFrom(rlang,"%@%")
importFrom(rlang,"%||%")
importFrom(rlang,":=")
importFrom(rlang,abort)
importFrom(rlang,as_function)
importFrom(rlang,caller_env)
importFrom(rlang,is_empty)
importFrom(rlang,global_env)
importFrom(rlang,is_null)
importFrom(rlang,quos)
importFrom(rlang,set_names)
importFrom(smoothqr,smooth_qr)
importFrom(stats,as.formula)
importFrom(stats,family)
Expand All @@ -255,8 +256,6 @@ importFrom(stats,predict)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,residuals)
importFrom(tibble,as_tibble)
importFrom(tibble,is_tibble)
importFrom(tibble,tibble)
importFrom(tidyr,drop_na)
importFrom(vctrs,as_list_of)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
- `arx_fcast_epi_workflow()` and `arx_class_epi_workflow()` now default to
`trainer = parsnip::logistic_reg()` to match their more canned versions.
- add a `forecast()` method simplify generating forecasts
- refactor `bake.epi_recipe()` and remove `epi_juice()`.
- Revise `compat-purrr` to use the r-lang `standalone-*` version (via
`{usethis}`)
104 changes: 0 additions & 104 deletions R/bake.epi_recipe.R

This file was deleted.

87 changes: 0 additions & 87 deletions R/compat-purrr.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
# See https://github.com/r-lib/rlang/blob/main/R/compat-purrr.R


map <- function(.x, .f, ...) {
.f <- rlang::as_function(.f, env = rlang::global_env())
lapply(.x, .f, ...)
}

walk <- function(.x, .f, ...) {
map(.x, .f, ...)
invisible(.x)
}

walk2 <- function(.x, .y, .f, ...) {
map2(.x, .y, .f, ...)
invisible(.x)
}

map_lgl <- function(.x, .f, ...) {
.rlang_purrr_map_mold(.x, .f, logical(1), ...)
}

map_int <- function(.x, .f, ...) {
.rlang_purrr_map_mold(.x, .f, integer(1), ...)
}

map_dbl <- function(.x, .f, ...) {
.rlang_purrr_map_mold(.x, .f, double(1), ...)
}

map_chr <- function(.x, .f, ...) {
.rlang_purrr_map_mold(.x, .f, character(1), ...)
}

map_vec <- function(.x, .f, ...) {
out <- map(.x, .f, ...)
vctrs::list_unchop(out)
Expand All @@ -48,61 +19,3 @@ map2_dfr <- function(.x, .y, .f, ..., .id = NULL) {
res <- map2(.x, .y, .f, ...)
dplyr::bind_rows(res, .id = .id)
}

.rlang_purrr_map_mold <- function(.x, .f, .mold, ...) {
.f <- rlang::as_function(.f, env = rlang::global_env())
out <- vapply(.x, .f, .mold, ..., USE.NAMES = FALSE)
names(out) <- names(.x)
out
}

.rlang_purrr_args_recycle <- function(args) {
lengths <- map_int(args, length)
n <- max(lengths)

stopifnot(all(lengths == 1L | lengths == n))
to_recycle <- lengths == 1L
args[to_recycle] <- map(args[to_recycle], function(x) rep.int(x, n))

args
}

map2 <- function(.x, .y, .f, ...) {
.f <- rlang::as_function(.f, env = rlang::global_env())
out <- mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE)
if (length(out) == length(.x)) {
rlang::set_names(out, names(.x))
} else {
rlang::set_names(out, NULL)
}
}
map2_lgl <- function(.x, .y, .f, ...) {
as.vector(map2(.x, .y, .f, ...), "logical")
}
map2_int <- function(.x, .y, .f, ...) {
as.vector(map2(.x, .y, .f, ...), "integer")
}
map2_dbl <- function(.x, .y, .f, ...) {
as.vector(map2(.x, .y, .f, ...), "double")
}
map2_chr <- function(.x, .y, .f, ...) {
as.vector(map2(.x, .y, .f, ...), "character")
}
imap <- function(.x, .f, ...) {
map2(.x, names(.x) %||% seq_along(.x), .f, ...)
}

pmap <- function(.l, .f, ...) {
.f <- as.function(.f)
args <- .rlang_purrr_args_recycle(.l)
do.call("mapply", c(
FUN = list(quote(.f)),
args, MoreArgs = quote(list(...)),
SIMPLIFY = FALSE, USE.NAMES = FALSE
))
}

reduce <- function(.x, .f, ..., .init) {
f <- function(x, y) .f(x, y, ...)
Reduce(f, .x, init = .init)
}
43 changes: 0 additions & 43 deletions R/epi_juice.R

This file was deleted.

22 changes: 22 additions & 0 deletions R/epi_recipe.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,28 @@ prep.epi_recipe <- function(
x
}

#' @export
bake.epi_recipe <- function(object, new_data, ..., composition = "epi_df") {
meta <- NULL
if (composition == "epi_df") {
if (is_epi_df(new_data)) {
meta <- attr(new_data, "metadata")
} else if (is_epi_df(object$template)) {
meta <- attr(object$template, "metadata")
}
composition <- "tibble"
}
new_data <- NextMethod("bake")
if (!is.null(meta)) {
new_data <- as_epi_df(
new_data, meta$geo_type, meta$time_type, meta$as_of,
meta$additional_metadata %||% list()
)
}
new_data
}


kill_levels <- function(x, keys) {
for (i in which(names(x) %in% keys)) x[[i]] <- list(values = NA, ordered = NA)
x
Expand Down
2 changes: 1 addition & 1 deletion R/epipredict-package.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## usethis namespace: start
#' @importFrom tibble tibble
#' @importFrom rlang := !! %||%
#' @importFrom rlang := !! %||% as_function global_env set_names
#' @importFrom stats poly predict lm residuals quantile
#' @importFrom cli cli_abort
#' @importFrom checkmate assert assert_character assert_int assert_scalar
Expand Down
10 changes: 8 additions & 2 deletions R/standalone-lifecycle.R → R/import-standalone-lifecycle.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Standalone file: do not edit by hand
# Source: <https://github.com/r-lib/rlang/blob/main/R/standalone-lifecycle.R>
# ----------------------------------------------------------------------
#
# ---
# repo: r-lib/rlang
# file: standalone-lifecycle.R
Expand Down Expand Up @@ -94,7 +98,8 @@ deprecate_soft <- function(msg,
id <- paste(id, collapse = "\n")
verbosity <- .rlang_lifecycle_verbosity()

invisible(switch(verbosity,
invisible(switch(
verbosity,
quiet = NULL,
warning = ,
default =
Expand All @@ -121,7 +126,8 @@ deprecate_warn <- function(msg,
id <- paste(id, collapse = "\n")
verbosity <- .rlang_lifecycle_verbosity()

invisible(switch(verbosity,
invisible(switch(
verbosity,
quiet = NULL,
warning = ,
default = {
Expand Down
Loading

0 comments on commit de6e1db

Please sign in to comment.