2828# ' The data table `DT` has key variables `geo_value`, `time_value`, `version`,
2929# ' as well as any others (these can be specified when instantiating the
3030# ' `epi_archive` object via the `other_keys` argument, and/or set by operating
31- # ' on `DT` directly). There can only be a single row per unique combination of
31+ # ' on `DT` directly). Refer to the documentation for [as_epi_archive()] for
32+ # ' information and examples of relevant parameter names for an `epi_archive` object.
33+ # ' Note that there can only be a single row per unique combination of
3234# ' key variables, and thus the key variables are critical for figuring out how
3335# ' to generate a snapshot of data from the archive, as of a given version.
34- # '
36+ # '
3537# ' In general, last observation carried forward (LOCF) is used to data in
3638# ' between recorded versions. Currently, deletions must be represented as
3739# ' revising a row to a special state (e.g., making the entries `NA` or
7880# '
7981# ' @importFrom R6 R6Class
8082# ' @export
83+ # ' @examples
84+ # ' tib <- tibble::tibble(
85+ # ' geo_value = rep(c("ca", "hi"), each = 5),
86+ # ' time_value = rep(seq(as.Date("2020-01-01"),
87+ # ' by = 1, length.out = 5), times = 2),
88+ # ' version = rep(seq(as.Date("2020-01-02"),
89+ # ' by = 1, length.out = 5), times = 2),
90+ # ' value = rnorm(10, mean = 2, sd = 1)
91+ # ' )
92+ # '
93+ # ' toy_epi_archive <- tib %>% epi_archive$new(geo_type = "state",
94+ # ' time_type = "day")
95+ # ' toy_epi_archive
8196epi_archive =
8297 R6 :: R6Class(
8398 classname = " epi_archive" ,
@@ -104,6 +119,10 @@ epi_archive =
104119# ' fields; named entries from the passed list or will be included as well.
105120# ' @return An `epi_archive` object.
106121# ' @importFrom data.table as.data.table key setkeyv
122+ # '
123+ # ' @details
124+ # ' Refer to the documentation for [as_epi_archive()] for more information
125+ # ' and examples of parameter names.
107126 initialize = function (x , geo_type , time_type , other_keys ,
108127 additional_metadata ) {
109128 # Check that we have a data frame
@@ -452,6 +471,21 @@ epi_archive =
452471# '
453472# ' @export
454473# ' @examples
474+ # ' # Simple ex. with necessary keys
475+ # ' tib <- tibble::tibble(
476+ # ' geo_value = rep(c("ca", "hi"), each = 5),
477+ # ' time_value = rep(seq(as.Date("2020-01-01"),
478+ # ' by = 1, length.out = 5), times = 2),
479+ # ' version = rep(seq(as.Date("2020-01-02"),
480+ # ' by = 1, length.out = 5), times = 2),
481+ # ' value = rnorm(10, mean = 2, sd = 1)
482+ # ' )
483+ # '
484+ # ' toy_epi_archive <- tib %>% as_epi_archive(geo_type = "state",
485+ # ' time_type = "day")
486+ # ' toy_epi_archive
487+ # '
488+ # ' # Ex. with an additional key for county
455489# ' df <- data.frame (geo_value = c(replicate(2, "ca"), replicate(2, "fl")),
456490# ' county = c(1, 3, 2, 5),
457491# ' time_value = c("2020-06-01",
0 commit comments