@@ -138,33 +138,45 @@ epix_as_of <- function(x, version, min_time_value = -Inf, all_versions = FALSE,
138
138
# ' Fill `epi_archive` unobserved history
139
139
# '
140
140
# ' @description
141
- # ' Sometimes, due to upstream data pipeline issues, we have to work with a
142
- # ' version history that isn't completely up to date, but with functions that
143
- # ' expect archives that are completely up to date, or equally as up-to-date as
144
- # ' another archive. This function provides one way to approach such mismatches:
145
- # ' pretend that we've "observed" additional versions, filling in these versions
146
- # ' with NAs or extrapolated values.
141
+ # ' This function fills in missing version history in an `epi_archive` object up
142
+ # ' to a specified version, updating the `versions_end` field as necessary. Note
143
+ # ' that the filling is done in a compactified way, see details.
147
144
# '
148
145
# ' @param x An `epi_archive`
149
- # ' @param fill_versions_end Length-1, same class&type as `x$version`: the
150
- # ' version through which to fill in missing version history; this will be the
151
- # ' result's `$versions_end` unless it already had a later
152
- # ' `$versions_end`.
153
- # ' @param how Optional; `"na"` or `"locf"`: `"na"` will fill in any missing
154
- # ' required version history with `NA`s, by inserting (if necessary) an update
155
- # ' immediately after the current `$versions_end` that revises all
156
- # ' existing measurements to be `NA` (this is only supported for `version`
157
- # ' classes with a `next_after` implementation); `"locf"` will fill in missing
158
- # ' version history with the last version of each observation carried forward
159
- # ' (LOCF), by leaving the update `$DT` alone (other `epi_archive` methods are
160
- # ' based on LOCF). Default is `"na"`.
146
+ # ' @param fill_versions_end a scalar of the same class&type as `x$version`: the
147
+ # ' version through which to fill in missing version history; the
148
+ # ' `epi_archive`'s `versions_end` attribute will be set to this, unless it
149
+ # ' already had a later `$versions_end`.
150
+ # ' @param how Optional; `"na"` or `"locf"`: `"na"` fills missing version history
151
+ # ' with `NA`s, `"locf"` fills missing version history with the last version of
152
+ # ' each observation carried forward (LOCF). Default is `"na"`.
153
+ # ' @return An `epi_archive`
154
+ # ' @details
155
+ # ' Note that we generally store `epi_archive`'s in a compacted form, meaning
156
+ # ' that, implciitly, if a version does not exist, but the `version_end`
157
+ # ' attribute is greater, then it is understood that all the versions in between
158
+ # ' had the same value as the last observed version. This affects the behavior of
159
+ # ' this function in the following ways:
160
+ # '
161
+ # ' - if `how = "na"`, then the function will fill in at most one missing version
162
+ # ' with `NA` and the rest will be implicit.
163
+ # ' - if `how = "locf"`, then the function will not fill any values.
161
164
# '
162
165
# ' @importFrom data.table copy ":="
163
166
# ' @importFrom rlang arg_match
164
167
# ' @return An `epi_archive`
165
168
# ' @export
166
- epix_fill_through_version <- function (x , fill_versions_end ,
167
- how = c(" na" , " locf" )) {
169
+ # ' @examples
170
+ # ' test_date <- as.Date("2020-01-01")
171
+ # ' ea_orig <- as_epi_archive(data.table::data.table(
172
+ # ' geo_value = "ak",
173
+ # ' time_value = test_date + c(rep(0L, 5L), 1L),
174
+ # ' version = test_date + c(1:5, 2L),
175
+ # ' value = 1:6
176
+ # ' ))
177
+ # ' epix_fill_through_version(ea_orig, test_date + 8, "na")
178
+ # ' epix_fill_through_version(ea_orig, test_date + 8, "locf")
179
+ epix_fill_through_version <- function (x , fill_versions_end , how = c(" na" , " locf" )) {
168
180
assert_class(x , " epi_archive" )
169
181
170
182
validate_version_bound(fill_versions_end , x $ DT , na_ok = FALSE )
0 commit comments