Skip to content

Commit de6e1db

Browse files
authored
Merge pull request #331 from cmu-delphi/djm/deprecate
Djm/deprecate
2 parents 5aa7828 + f9c1f8f commit de6e1db

19 files changed

+318
-306
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: epipredict
22
Title: Basic epidemiology forecasting methods
3-
Version: 0.0.14
3+
Version: 0.0.15
44
Authors@R: c(
55
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
@@ -38,7 +38,7 @@ Imports:
3838
magrittr,
3939
quantreg,
4040
recipes (>= 1.0.4),
41-
rlang,
41+
rlang (>= 1.0.0),
4242
smoothqr,
4343
stats,
4444
tibble,

NAMESPACE

+3-4
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,11 @@ importFrom(rlang,"%@%")
240240
importFrom(rlang,"%||%")
241241
importFrom(rlang,":=")
242242
importFrom(rlang,abort)
243+
importFrom(rlang,as_function)
243244
importFrom(rlang,caller_env)
244-
importFrom(rlang,is_empty)
245+
importFrom(rlang,global_env)
245246
importFrom(rlang,is_null)
246-
importFrom(rlang,quos)
247+
importFrom(rlang,set_names)
247248
importFrom(smoothqr,smooth_qr)
248249
importFrom(stats,as.formula)
249250
importFrom(stats,family)
@@ -255,8 +256,6 @@ importFrom(stats,predict)
255256
importFrom(stats,qnorm)
256257
importFrom(stats,quantile)
257258
importFrom(stats,residuals)
258-
importFrom(tibble,as_tibble)
259-
importFrom(tibble,is_tibble)
260259
importFrom(tibble,tibble)
261260
importFrom(tidyr,drop_na)
262261
importFrom(vctrs,as_list_of)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
4343
- `arx_fcast_epi_workflow()` and `arx_class_epi_workflow()` now default to
4444
`trainer = parsnip::logistic_reg()` to match their more canned versions.
4545
- add a `forecast()` method simplify generating forecasts
46+
- refactor `bake.epi_recipe()` and remove `epi_juice()`.
47+
- Revise `compat-purrr` to use the r-lang `standalone-*` version (via
48+
`{usethis}`)

R/bake.epi_recipe.R

-104
This file was deleted.

R/compat-purrr.R

-87
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
1-
# See https://github.com/r-lib/rlang/blob/main/R/compat-purrr.R
2-
3-
4-
map <- function(.x, .f, ...) {
5-
.f <- rlang::as_function(.f, env = rlang::global_env())
6-
lapply(.x, .f, ...)
7-
}
8-
9-
walk <- function(.x, .f, ...) {
10-
map(.x, .f, ...)
11-
invisible(.x)
12-
}
13-
141
walk2 <- function(.x, .y, .f, ...) {
152
map2(.x, .y, .f, ...)
163
invisible(.x)
174
}
185

19-
map_lgl <- function(.x, .f, ...) {
20-
.rlang_purrr_map_mold(.x, .f, logical(1), ...)
21-
}
22-
23-
map_int <- function(.x, .f, ...) {
24-
.rlang_purrr_map_mold(.x, .f, integer(1), ...)
25-
}
26-
27-
map_dbl <- function(.x, .f, ...) {
28-
.rlang_purrr_map_mold(.x, .f, double(1), ...)
29-
}
30-
31-
map_chr <- function(.x, .f, ...) {
32-
.rlang_purrr_map_mold(.x, .f, character(1), ...)
33-
}
34-
356
map_vec <- function(.x, .f, ...) {
367
out <- map(.x, .f, ...)
378
vctrs::list_unchop(out)
@@ -48,61 +19,3 @@ map2_dfr <- function(.x, .y, .f, ..., .id = NULL) {
4819
res <- map2(.x, .y, .f, ...)
4920
dplyr::bind_rows(res, .id = .id)
5021
}
51-
52-
.rlang_purrr_map_mold <- function(.x, .f, .mold, ...) {
53-
.f <- rlang::as_function(.f, env = rlang::global_env())
54-
out <- vapply(.x, .f, .mold, ..., USE.NAMES = FALSE)
55-
names(out) <- names(.x)
56-
out
57-
}
58-
59-
.rlang_purrr_args_recycle <- function(args) {
60-
lengths <- map_int(args, length)
61-
n <- max(lengths)
62-
63-
stopifnot(all(lengths == 1L | lengths == n))
64-
to_recycle <- lengths == 1L
65-
args[to_recycle] <- map(args[to_recycle], function(x) rep.int(x, n))
66-
67-
args
68-
}
69-
70-
map2 <- function(.x, .y, .f, ...) {
71-
.f <- rlang::as_function(.f, env = rlang::global_env())
72-
out <- mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE)
73-
if (length(out) == length(.x)) {
74-
rlang::set_names(out, names(.x))
75-
} else {
76-
rlang::set_names(out, NULL)
77-
}
78-
}
79-
map2_lgl <- function(.x, .y, .f, ...) {
80-
as.vector(map2(.x, .y, .f, ...), "logical")
81-
}
82-
map2_int <- function(.x, .y, .f, ...) {
83-
as.vector(map2(.x, .y, .f, ...), "integer")
84-
}
85-
map2_dbl <- function(.x, .y, .f, ...) {
86-
as.vector(map2(.x, .y, .f, ...), "double")
87-
}
88-
map2_chr <- function(.x, .y, .f, ...) {
89-
as.vector(map2(.x, .y, .f, ...), "character")
90-
}
91-
imap <- function(.x, .f, ...) {
92-
map2(.x, names(.x) %||% seq_along(.x), .f, ...)
93-
}
94-
95-
pmap <- function(.l, .f, ...) {
96-
.f <- as.function(.f)
97-
args <- .rlang_purrr_args_recycle(.l)
98-
do.call("mapply", c(
99-
FUN = list(quote(.f)),
100-
args, MoreArgs = quote(list(...)),
101-
SIMPLIFY = FALSE, USE.NAMES = FALSE
102-
))
103-
}
104-
105-
reduce <- function(.x, .f, ..., .init) {
106-
f <- function(x, y) .f(x, y, ...)
107-
Reduce(f, .x, init = .init)
108-
}

R/epi_juice.R

-43
This file was deleted.

R/epi_recipe.R

+22
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,28 @@ prep.epi_recipe <- function(
557557
x
558558
}
559559

560+
#' @export
561+
bake.epi_recipe <- function(object, new_data, ..., composition = "epi_df") {
562+
meta <- NULL
563+
if (composition == "epi_df") {
564+
if (is_epi_df(new_data)) {
565+
meta <- attr(new_data, "metadata")
566+
} else if (is_epi_df(object$template)) {
567+
meta <- attr(object$template, "metadata")
568+
}
569+
composition <- "tibble"
570+
}
571+
new_data <- NextMethod("bake")
572+
if (!is.null(meta)) {
573+
new_data <- as_epi_df(
574+
new_data, meta$geo_type, meta$time_type, meta$as_of,
575+
meta$additional_metadata %||% list()
576+
)
577+
}
578+
new_data
579+
}
580+
581+
560582
kill_levels <- function(x, keys) {
561583
for (i in which(names(x) %in% keys)) x[[i]] <- list(values = NA, ordered = NA)
562584
x

R/epipredict-package.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## usethis namespace: start
22
#' @importFrom tibble tibble
3-
#' @importFrom rlang := !! %||%
3+
#' @importFrom rlang := !! %||% as_function global_env set_names
44
#' @importFrom stats poly predict lm residuals quantile
55
#' @importFrom cli cli_abort
66
#' @importFrom checkmate assert assert_character assert_int assert_scalar

R/standalone-lifecycle.R R/import-standalone-lifecycle.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Standalone file: do not edit by hand
2+
# Source: <https://github.com/r-lib/rlang/blob/main/R/standalone-lifecycle.R>
3+
# ----------------------------------------------------------------------
4+
#
15
# ---
26
# repo: r-lib/rlang
37
# file: standalone-lifecycle.R
@@ -94,7 +98,8 @@ deprecate_soft <- function(msg,
9498
id <- paste(id, collapse = "\n")
9599
verbosity <- .rlang_lifecycle_verbosity()
96100

97-
invisible(switch(verbosity,
101+
invisible(switch(
102+
verbosity,
98103
quiet = NULL,
99104
warning = ,
100105
default =
@@ -121,7 +126,8 @@ deprecate_warn <- function(msg,
121126
id <- paste(id, collapse = "\n")
122127
verbosity <- .rlang_lifecycle_verbosity()
123128

124-
invisible(switch(verbosity,
129+
invisible(switch(
130+
verbosity,
125131
quiet = NULL,
126132
warning = ,
127133
default = {

0 commit comments

Comments
 (0)