Skip to content

Commit 0b6c273

Browse files
authored
Merge pull request #70 from cmu-delphi/is_epi_df
Is epi df
2 parents 22ceefa + 0c3ec4b commit 0b6c273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+972
-142
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Authors@R:
2424
role = "aut"),
2525
person(given = "Dmitry",
2626
family = "Shemetov",
27-
role = "aut"),
27+
role = "ctb"),
2828
person(given = "Ryan",
2929
family = "Tibshirani",
3030
role = c("aut", "cre"),

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export(epix_as_of)
3232
export(epix_merge)
3333
export(epix_slide)
3434
export(growth_rate)
35+
export(is_epi_archive)
36+
export(is_epi_df)
3537
export(quiet)
3638
importFrom(data.table,as.data.table)
3739
importFrom(data.table,between)

R/archive.R

+10
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,13 @@ as_epi_archive = function(x, geo_type, time_type, other_keys,
451451
additional_metadata = list()) {
452452
epi_archive$new(x, geo_type, time_type, other_keys, additional_metadata)
453453
}
454+
455+
#' Test for `epi_archive` format
456+
#'
457+
#' @param x An object.
458+
#' @return `TRUE` if the object inherits from `epi_archive`.
459+
#'
460+
#' @export
461+
is_epi_archive = function(x) {
462+
inherits(x, "epi_archive")
463+
}

R/epi_df.R

+28-18
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
#' and metadata. It can be seen as a snapshot of a data set that contains the
55
#' most up-to-date values of some signal variables of interest, as of a given
66
#' time.
7-
#'
8-
#' @details An `epi_df` is a tibble with (at least) the following columns:
9-
#'
7+
#'
8+
#' @details An `epi_df` is a tibble with (at least) the following columns:
9+
#'
1010
#' * `geo_value`: the geographic value associated with each row of measurements.
1111
#' * `time_value`: the time value associated with each row of measurements.
1212
#'
1313
#' Other columns can be considered as measured variables, which we also refer to
1414
#' as signal variables. An `epi_df` object also has metadata with (at least)
15-
#' the following fields:
16-
#'
15+
#' the following fields:
16+
#'
1717
#' * `geo_type`: the type for the geo values.
1818
#' * `time_type`: the type for the time values.
1919
#' * `as_of`: the time value at which the given data were available.
@@ -42,25 +42,25 @@
4242
#'
4343
#' @section Geo Types:
4444
#' The following geo types are recognized in an `epi_df`.
45-
#'
45+
#'
4646
#' * `"county"`: each observation corresponds to a U.S. county; coded by 5-digit
47-
#' FIPS code.
47+
#' FIPS code.
4848
#' * `"hrr"`: each observation corresponds to a U.S. hospital referral region
4949
#' (designed to represent regional healthcare markets); there are 306 HRRs in
5050
#' the U.S; coded by number (nonconsecutive, between 1 and 457).
5151
#' * `"state"`: each observation corresponds to a U.S. state; coded by 2-digit
52-
#' postal abbreviation (lowercase);
53-
#' note that Puerto Rico is "pr" and Washington D.C. is "dc".
52+
#' postal abbreviation (lowercase);
53+
#' note that Puerto Rico is "pr" and Washington D.C. is "dc".
5454
#' * `"hhs"`: each observation corresponds to a U.S. HHS region; coded by number
5555
#' (consecutive, between 1 and 10).
5656
#' * `"nation"`: each observation corresponds to a country; coded by ISO 31661-
5757
#' alpha-2 country codes (lowercase).
5858
#'
5959
#' An unrecognizable geo type is labeled "custom".
60-
#'
60+
#'
6161
#' @section Time Types:
6262
#' The following time types are recognized in an `epi_df`.
63-
#'
63+
#'
6464
#' * `"day-time"`: each observation corresponds to a time on a given day
6565
#' (measured to the second); coded as a `POSIXct` object, as in
6666
#' `as.POSIXct("2022-01-31 18:45:40")`.
@@ -71,7 +71,7 @@
7171
#' `Date` object, representing the start date of week.
7272
#' * `"yearweek"`: each observation corresponds to a week; the alignment can be
7373
#' arbitrary; coded as a `tsibble::yearweek` object, where the alignment is
74-
#' stored in the `week_start` field of its attributes.
74+
#' stored in the `week_start` field of its attributes.
7575
#' * `"yearmonth"`: each observation corresponds to a month; coded as a
7676
#' `tsibble::yearmonth` object.
7777
#' * `"yearquarter"`: each observation corresponds to a quarter; coded as a
@@ -108,7 +108,7 @@ NULL
108108
#' well.
109109
#' @param ... Additional arguments passed to methods.
110110
#' @return An `epi_df` object.
111-
#'
111+
#'
112112
#' @export
113113
as_epi_df = function(x, ...) {
114114
UseMethod("as_epi_df")
@@ -158,13 +158,13 @@ as_epi_df.tbl_df = function(x, geo_type, time_type, as_of,
158158
"as_of" %in% names(attributes(x)$metadata)) {
159159
as_of = attributes(x)$metadata$as_of
160160
}
161-
161+
162162
# Next check for as_of, issue, or version columns
163163
else if ("as_of" %in% names(x)) as_of = max(x$as_of)
164164
else if ("issue" %in% names(x)) as_of = max(x$issue)
165165
else if ("version" %in% names(x)) as_of = max(x$version)
166166

167-
# If we got here then we failed
167+
# If we got here then we failed
168168
else as_of = Sys.time() # Use the current day-time
169169
}
170170

@@ -174,10 +174,10 @@ as_epi_df.tbl_df = function(x, geo_type, time_type, as_of,
174174
metadata$time_type = time_type
175175
metadata$as_of = as_of
176176
metadata = c(metadata, additional_metadata)
177-
178-
# Reorder columns (geo_value, time_value, ...)
177+
178+
# Reorder columns (geo_value, time_value, ...)
179179
x = dplyr::relocate(x, .data$geo_value, .data$time_value)
180-
180+
181181
# Apply epi_df class, attach metadata, and return
182182
class(x) = c("epi_df", class(x))
183183
attributes(x)$metadata = metadata
@@ -209,3 +209,13 @@ as_epi_df.tbl_ts = function(x, geo_type, time_type, as_of,
209209
as_epi_df.tbl_df(tibble::as_tibble(x), geo_type, time_type, as_of,
210210
additional_metadata, ...)
211211
}
212+
213+
#' Test for `epi_df` format
214+
#'
215+
#' @param x An object.
216+
#' @return `TRUE` if the object inherits from `epi_df`.
217+
#'
218+
#' @export
219+
is_epi_df = function(x) {
220+
inherits(x, "epi_df")
221+
}

_pkgdown.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ reference:
3535
- contents:
3636
- epi_df
3737
- as_epi_df
38-
- as_tsibble
38+
- is_epi_df
39+
- as_tsibble.epi_df
3940
- print.epi_df
4041
- title: epi_*() functions
4142
desc: Functions that act on `epi_df` objects.
@@ -54,6 +55,7 @@ reference:
5455
- contents:
5556
- epi_archive
5657
- as_epi_archive
58+
- is_epi_archive
5759
- title: epix_*() functions
5860
desc: Functions that act on an `epi_archive` object.
5961
- contents:

docs/404.html

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

docs/LICENSE-text.html

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

0 commit comments

Comments
 (0)