Skip to content

Commit ea28a15

Browse files
committed
Fix incomplete merge, inaccurate new_epi_df(*_type) docs
1 parent db115cf commit ea28a15

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

R/epi_df.R

+24-15
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,30 @@
151151
#' attr(ex3, "metadata")
152152
NULL
153153

154-
#' Create an `epi_df` object
155-
#'
156-
#' @rdname epi_df
157-
#' @param geo_type DEPRECATED Has no effect. Geo value type is inferred from the
158-
#' location column and set to "custom" if not recognized.
159-
#' @param time_type DEPRECATED Has no effect. Time value type inferred from the time
160-
#' column and set to "custom" if not recognized. Unpredictable behavior may result
161-
#' if the time type is not recognized.
154+
#' @describeIn epi_df Lower-level constructor for `epi_df` object
155+
#' @order 2
156+
#' @param geo_type `r lifecycle::badge("deprecated")` in `as_epi_df()`, has no
157+
#' effect; the geo value type is inferred from the location column and set to
158+
#' "custom" if not recognized. In `new_epi_df()`, should be set to the same
159+
#' value that would be inferred.
160+
#' @param time_type `r lifecycle::badge("deprecated")` in `as_epi_df()`, has no
161+
#' effect: the time value type inferred from the time column and set to
162+
#' "custom" if not recognized. Unpredictable behavior may result if the time
163+
#' type is not recognized. In `new_epi_df()`, should be set to the same value
164+
#' that would be inferred.
162165
#' @param as_of Time value representing the time at which the given data were
163166
#' available. For example, if `as_of` is January 31, 2022, then the `epi_df`
164167
#' object that is created would represent the most up-to-date version of the
165168
#' data available as of January 31, 2022. If the `as_of` argument is missing,
166169
#' then the current day-time will be used.
167-
#' @param other_keys If your tibble has additional keys, be sure to specify them as a
168-
#' character vector here (typical examples are "age" or sub-geographies).
170+
#' @param other_keys If your tibble has additional keys, be sure to specify them
171+
#' as a character vector here (typical examples are "age" or sub-geographies).
169172
#' @param ... Additional arguments passed to methods.
170173
#' @return An `epi_df` object.
171174
#'
172175
#' @export
173-
new_epi_df <- function(x = tibble::tibble(), geo_type, time_type, as_of,
176+
new_epi_df <- function(x = tibble::tibble(geo_value = character(), time_value = as.Date(integer())),
177+
geo_type, time_type, as_of,
174178
other_keys = character(), ...) {
175179
# Define metadata fields
176180
metadata <- list()
@@ -195,7 +199,8 @@ new_epi_df <- function(x = tibble::tibble(), geo_type, time_type, as_of,
195199
return(x)
196200
}
197201

198-
#' @rdname epi_df
202+
#' @describeIn epi_df The preferred way of constructing `epi_df`s
203+
#' @order 1
199204
#' @param x An `epi_df`, `data.frame`, [tibble::tibble], or [tsibble::tsibble]
200205
#' to be converted
201206
#' @param ... used for specifying column names, as in [`dplyr::rename`]. For
@@ -206,17 +211,19 @@ as_epi_df <- function(x, ...) {
206211
}
207212

208213
#' @rdname epi_df
214+
#' @order 1
209215
#' @method as_epi_df epi_df
210216
#' @export
211217
as_epi_df.epi_df <- function(x, ...) {
212218
return(x)
213219
}
214220

215221
#' @rdname epi_df
216-
#' @method as_epi_df tbl_df
222+
#' @order 1
217223
#' @importFrom rlang .data
218224
#' @importFrom tidyselect any_of
219225
#' @importFrom cli cli_inform
226+
#' @method as_epi_df tbl_df
220227
#' @export
221228
as_epi_df.tbl_df <- function(
222229
x,
@@ -273,15 +280,17 @@ as_epi_df.tbl_df <- function(
273280
new_epi_df(x, geo_type, time_type, as_of, other_keys)
274281
}
275282

276-
#' @method as_epi_df data.frame
277283
#' @rdname epi_df
284+
#' @order 1
285+
#' @method as_epi_df data.frame
278286
#' @export
279287
as_epi_df.data.frame <- function(x, as_of, other_keys = character(), ...) {
280288
as_epi_df.tbl_df(x = tibble::as_tibble(x), as_of = as_of, other_keys = other_keys, ...)
281289
}
282290

283-
#' @method as_epi_df tbl_ts
284291
#' @rdname epi_df
292+
#' @order 1
293+
#' @method as_epi_df tbl_ts
285294
#' @export
286295
as_epi_df.tbl_ts <- function(x, as_of, other_keys = character(), ...) {
287296
tsibble_other_keys <- setdiff(tsibble::key_vars(x), "geo_value")

man/epi_df.Rd

+32-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-arrange-canonical.R

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ test_that("canonical arrangement works", {
77
)
88
expect_error(arrange_canonical(tib))
99

10-
tib <- tib %>% as_epi_df(additional_metadata = list(other_keys = "demo_grp"))
11-
expect_equal(names(tib), c("geo_value", "time_value", "x", "demo_grp"))
10+
tib <- tib %>% as_epi_df(other_keys = "demo_grp")
11+
expect_equal(names(tib), c("geo_value", "time_value", "demo_grp", "x"))
1212

13-
tib_sorted <- arrange_canonical(tib)
13+
tib_cols_shuffled <- tib %>% select(geo_value, time_value, x, demo_grp)
14+
15+
tib_sorted <- arrange_canonical(tib_cols_shuffled)
1416
expect_equal(names(tib_sorted), c("geo_value", "time_value", "demo_grp", "x"))
1517
expect_equal(tib_sorted$geo_value, rep(c("ca", "ga"), each = 4))
1618
expect_equal(tib_sorted$time_value, c(1, 1, 2, 2, 1, 1, 2, 2))

0 commit comments

Comments
 (0)