Skip to content

Commit 8271a97

Browse files
committed
Change "LVCF" back to "LOCF", but with consistent intro text
Always introduce version-wise LOCF as "last observation of each observation carried forward (LOCF)" or something quite similar. Clarify time-wise LOCF in one place.
1 parent b2bde0e commit 8271a97

14 files changed

+124
-120
lines changed

R/archive.R

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ next_after.Date = function(x) x + 1L
128128
#' key variables, and thus the key variables are critical for figuring out how
129129
#' to generate a snapshot of data from the archive, as of a given version.
130130
#'
131-
#' In general, the last version of each observation is carried forward (LVCF) to
131+
#' In general, the last version of each observation is carried forward (LOCF) to
132132
#' fill in data between recorded versions, and between the last recorded
133133
#' update and the `observed_versions_end`. One consequence is that the `DT`
134134
#' doesn't have to contain a full snapshot of every version (although this
@@ -230,8 +230,8 @@ epi_archive =
230230
#' @param compactify Optional; Boolean or `NULL`: should we remove rows that are
231231
#' considered redundant for the purposes of `epi_archive`'s built-in methods
232232
#' such as `as_of`? As these methods use the last version of each observation
233-
#' carried forward (LVCF) to interpolate between the version data provided,
234-
#' rows that don't change these LVCF results can potentially be omitted to
233+
#' carried forward (LOCF) to interpolate between the version data provided,
234+
#' rows that don't change these LOCF results can potentially be omitted to
235235
#' save space while maintaining the same behavior (with the help of the
236236
#' `clobberable_versions_start` and `observed_versions_end` fields in some
237237
#' edge cases). `TRUE` will remove these rows, `FALSE` will not, and missing
@@ -337,30 +337,30 @@ epi_archive =
337337
DT = as.data.table(x, key = key_vars)
338338
if (!identical(key_vars, key(DT))) setkeyv(DT, cols = key_vars)
339339

340-
# Checks to see if a value in a vector is LVCF
341-
is_lvcf <- function(vec) {
340+
# Checks to see if a value in a vector is LOCF
341+
is_locf <- function(vec) {
342342
dplyr::if_else(!is.na(vec) & !is.na(dplyr::lag(vec)),
343343
vec == dplyr::lag(vec),
344344
is.na(vec) & is.na(dplyr::lag(vec)))
345345
}
346346

347-
# LVCF is defined by a row where all values except for the version
347+
# LOCF is defined by a row where all values except for the version
348348
# differ from their respective lag values
349349

350-
# Checks for LVCF's in a data frame
351-
rm_lvcf <- function(df) {
352-
dplyr::filter(df,if_any(c(everything(),-version),~ !is_lvcf(.)))
350+
# Checks for LOCF's in a data frame
351+
rm_locf <- function(df) {
352+
dplyr::filter(df,if_any(c(everything(),-version),~ !is_locf(.)))
353353
}
354354

355-
# Keeps LVCF values, such as to be printed
356-
keep_lvcf <- function(df) {
357-
dplyr::filter(df,if_all(c(everything(),-version),~ is_lvcf(.)))
355+
# Keeps LOCF values, such as to be printed
356+
keep_locf <- function(df) {
357+
dplyr::filter(df,if_all(c(everything(),-version),~ is_locf(.)))
358358
}
359359

360360
# Runs compactify on data frame
361361
if (is.null(compactify) || compactify == TRUE) {
362-
elim = keep_lvcf(DT)
363-
DT = rm_lvcf(DT)
362+
elim = keep_locf(DT)
363+
DT = rm_locf(DT)
364364
} else {
365365
# Create empty data frame for nrow(elim) to be 0
366366
elim = tibble::tibble()
@@ -370,7 +370,7 @@ epi_archive =
370370
if (is.null(compactify) && nrow(elim) > 0) {
371371
warning_intro <- break_str(paste(
372372
'Found rows that appear redundant based on',
373-
'last (version of an) observation carried forward;',
373+
'last (version of each) observation carried forward;',
374374
'these rows have been removed to "compactify" and save space:'
375375
))
376376

@@ -494,7 +494,7 @@ epi_archive =
494494
#' @importFrom data.table key setkeyv := address copy
495495
#' @importFrom rlang arg_match
496496
fill_through_version = function(fill_versions_end,
497-
how=c("na", "lvcf")) {
497+
how=c("na", "locf")) {
498498
validate_version_bound(fill_versions_end, self$DT, na_ok=FALSE)
499499
how <- arg_match(how)
500500
if (self$observed_versions_end < fill_versions_end) {
@@ -532,8 +532,8 @@ epi_archive =
532532
# full result DT:
533533
setkeyv(rbind(self$DT, next_version_DT), key(self$DT))[]
534534
},
535-
"lvcf" = {
536-
# just the old DT; LVCF is built into other methods:
535+
"locf" = {
536+
# just the old DT; LOCF is built into other methods:
537537
self$DT
538538
}
539539
)
@@ -557,7 +557,7 @@ epi_archive =
557557
#' @param y as in [`epix_merge`]
558558
#' @param observed_versions_end_conflict as in [`epix_merge`]
559559
#' @param compactify as in [`epix_merge`]
560-
merge = function(y, observed_versions_end_conflict = c("stop","na","lvcf","truncate"), compactify=TRUE) {
560+
merge = function(y, observed_versions_end_conflict = c("stop","na","locf","truncate"), compactify=TRUE) {
561561
result = epix_merge(self, y,
562562
observed_versions_end_conflict = observed_versions_end_conflict,
563563
compactify = compactify)
@@ -751,8 +751,8 @@ epi_archive =
751751
#' @param compactify Optional; Boolean or `NULL`: should we remove rows that are
752752
#' considered redundant for the purposes of `epi_archive`'s built-in methods
753753
#' such as `as_of`? As these methods use the last version of each observation
754-
#' carried forward (LVCF) to interpolate between the version data provided,
755-
#' rows that don't change these LVCF results can potentially be omitted to
754+
#' carried forward (LOCF) to interpolate between the version data provided,
755+
#' rows that don't change these LOCF results can potentially be omitted to
756756
#' save space. `TRUE` will remove these rows, `FALSE` will not, and missing or
757757
#' `NULL` will remove these rows and issue a warning. Generally, this can be
758758
#' set to `TRUE`, but if you directly inspect or edit the fields of the

R/methods-epi_archive.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
#' max_version = as.Date("2020-06-12"))
4242
#'
4343
#' # When fetching a snapshot as of the latest version with update data in the
44-
#' # archive, a warning is issued as this update data might not yet be finalized
45-
#' # (for example, if data versions are labeled with dates, these versions might be
46-
#' # overwritten throughout the day if the data can be updated multiple times per
47-
#' # day; when we build an archive based on special update-data queries all made at
48-
#' # the same time, the latest available update might still be subject to change,
49-
#' # but previous versions should be finalized). We can muffle such warnings with
50-
#' # the following pattern:
44+
#' # archive, a warning is issued by default, as this update data might not yet
45+
#' # be finalized (for example, if data versions are labeled with dates, these
46+
#' # versions might be overwritten throughout the corresponding days with
47+
#' # additional data or "hotfixes" of erroroneous data; when we build an archive
48+
#' # based on database queries, the latest available update might still be
49+
#' # subject to change, but previous versions should be finalized). We can
50+
#' # muffle such warnings with the following pattern:
5151
#' withCallingHandlers({
5252
#' epix_as_of(x = archive_cases_dv_subset,
5353
#' max_version = max(archive_cases_dv_subset$DT$version))
@@ -80,17 +80,17 @@ epix_as_of = function(x, max_version, min_time_value = -Inf) {
8080
#' version through which to fill in missing version history; this will be the
8181
#' result's `$observed_versions_end` unless it already had a later
8282
#' `$observed_versions_end`.
83-
#' @param how Optional; `"na"` or `"lvcf"`: `"na"` will fill in any missing
83+
#' @param how Optional; `"na"` or `"locf"`: `"na"` will fill in any missing
8484
#' required version history with `NA`s, by inserting (if necessary) an update
8585
#' immediately after the current `$observed_versions_end` that revises all
8686
#' existing measurements to be `NA` (this is only supported for `version`
87-
#' classes with a `next_after` implementation); `"lvcf"` will fill in missing
87+
#' classes with a `next_after` implementation); `"locf"` will fill in missing
8888
#' version history with the last version of each observation carried forward
89-
#' (LVCF), by leaving the update `$DT` alone (other `epi_archive` methods are
90-
#' based on LVCF). Default is `"na"`.
89+
#' (LOCF), by leaving the update `$DT` alone (other `epi_archive` methods are
90+
#' based on LOCF). Default is `"na"`.
9191
#' @return An `epi_archive`
9292
epix_fill_through_version = function(x, fill_versions_end,
93-
how=c("na", "lvcf")) {
93+
how=c("na", "locf")) {
9494
if (!inherits(x, "epi_archive")) Abort("`x` must be of class `epi_archive`.")
9595
# Enclosing parentheses drop the invisibility flag. See description above of
9696
# potential mutation and aliasing behavior.
@@ -115,17 +115,17 @@ epix_fill_through_version = function(x, fill_versions_end,
115115
#' old `DT` in another object).
116116
#'
117117
#' @param x,y Two `epi_archive` objects to join together.
118-
#' @param observed_versions_end_conflict Optional; `"stop"`, `"na"`, `"lvcf"`,
118+
#' @param observed_versions_end_conflict Optional; `"stop"`, `"na"`, `"locf"`,
119119
#' or `"truncate"`; in the case that `x$observed_versions_end` doesn't match
120120
#' `y$observed_versions_end`, what do we do?: `"stop"`: emit an error; "na":
121121
#' use `max(x$observed_versions_end, y$observed_versions_end)`, but in the
122122
#' less up-to-date input archive, imagine there was an update immediately
123123
#' after its last observed version which revised all observations to be `NA`;
124-
#' `"lvcf"`: use `max(x$observed_versions_end, y$observed_versions_end)`, and
125-
#' last-version-carried-forward extrapolation to invent update data for the
126-
#' less up-to-date input archive; or `"truncate"`: use
127-
#' `min(x$observed_versions_end, y$observed_versions_end)` and discard any
128-
#' rows containing update rows for later versions.
124+
#' `"locf"`: use `max(x$observed_versions_end, y$observed_versions_end)`,
125+
#' allowing the last version of each observation to be carried forward to
126+
#' extrapolate unavailable versions for the less up-to-date input archive; or
127+
#' `"truncate"`: use `min(x$observed_versions_end, y$observed_versions_end)`
128+
#' and discard any rows containing update rows for later versions.
129129
#' @param compactify Optional; `TRUE`, `FALSE`, or `NULL`; should the result be
130130
#' compactified? See [`as_epi_archive`] for an explanation of what this means.
131131
#' Default here is `TRUE`.
@@ -151,7 +151,7 @@ epix_fill_through_version = function(x, fill_versions_end,
151151
#' @importFrom data.table key set
152152
#' @export
153153
epix_merge = function(x, y,
154-
observed_versions_end_conflict = c("stop","na","lvcf","truncate"),
154+
observed_versions_end_conflict = c("stop","na","locf","truncate"),
155155
compactify = TRUE) {
156156
if (!inherits(x, "epi_archive")) {
157157
Abort("`x` must be of class `epi_archive`.")
@@ -205,7 +205,7 @@ epix_merge = function(x, y,
205205
x_DT = x$DT
206206
y_DT = y$DT
207207
}
208-
} else if (observed_versions_end_conflict %in% c("na", "lvcf")) {
208+
} else if (observed_versions_end_conflict %in% c("na", "locf")) {
209209
new_observed_versions_end = max(x$observed_versions_end, y$observed_versions_end)
210210
x_DT = epix_fill_through_version(x, new_observed_versions_end, observed_versions_end_conflict)$DT
211211
y_DT = epix_fill_through_version(y, new_observed_versions_end, observed_versions_end_conflict)$DT

data-raw/archive_cases_dv_subset.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ case_rate_subset <- covidcast(
3232
as_epi_archive(compactify=FALSE)
3333

3434
archive_cases_dv_subset = epix_merge(dv_subset, case_rate_subset,
35-
observed_versions_end_conflict="lvcf",
35+
observed_versions_end_conflict="locf",
3636
compactify=FALSE)
3737

3838
# If we directly store an epi_archive R6 object as data, it will store its class

man/as_epi_archive.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/as_epi_df.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_archive.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epix_as_of.Rd

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epix_fill_through_version.Rd

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)