Skip to content

Commit a71c3fe

Browse files
committed
Rename versions_end_conflict -> sync, "stop" -> "forbid"
1 parent 155ea73 commit a71c3fe

File tree

7 files changed

+68
-60
lines changed

7 files changed

+68
-60
lines changed

R/archive.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,11 @@ epi_archive =
555555
#' of the non-R6-method version, which does not mutate either archive, and
556556
#' does not alias either archive's `DT`.
557557
#' @param y as in [`epix_merge`]
558-
#' @param versions_end_conflict as in [`epix_merge`]
558+
#' @param sync as in [`epix_merge`]
559559
#' @param compactify as in [`epix_merge`]
560-
merge = function(y, versions_end_conflict = c("stop","na","locf","truncate"), compactify=TRUE) {
560+
merge = function(y, sync = c("forbid","na","locf","truncate"), compactify = TRUE) {
561561
result = epix_merge(self, y,
562-
versions_end_conflict = versions_end_conflict,
562+
sync = sync,
563563
compactify = compactify)
564564

565565
if (length(epi_archive$private_fields) != 0L) {

R/methods-epi_archive.R

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ epix_fill_through_version = function(x, fill_versions_end,
105105
#' `y` individually, then performing a full join of the `DT`s on the non-version
106106
#' key columns (potentially consolidating multiple warnings about clobberable
107107
#' versions). If the `versions_end` values differ, the
108-
#' `versions_end_conflict` parameter controls what is done.
108+
#' `sync` parameter controls what is done.
109109
#'
110110
#' This function, [`epix_merge`], does not mutate its inputs and will not alias
111111
#' either archive's `DT`, but may alias other fields; `x$merge` will overwrite
@@ -115,16 +115,20 @@ 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 versions_end_conflict Optional; `"stop"`, `"na"`, `"locf"`,
119-
#' or `"truncate"`; in the case that `x$versions_end` doesn't match
120-
#' `y$versions_end`, what do we do?: `"stop"`: emit an error; "na":
121-
#' use `max(x$versions_end, y$versions_end)`, but in the
122-
#' less up-to-date input archive, imagine there was an update immediately
123-
#' after its last observed version which revised all observations to be `NA`;
124-
#' `"locf"`: use `max(x$versions_end, y$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$versions_end, y$versions_end)`
118+
#' @param sync Optional; `"forbid"`, `"na"`, `"locf"`, or `"truncate"`; in the
119+
#' case that `x$versions_end` doesn't match `y$versions_end`, what do we do?:
120+
#' `"forbid"`: emit an error; "na": use `max(x$versions_end, y$versions_end)`
121+
#' as the result's `versions_end`, but ensure that, if we request a snapshot
122+
#' as of a version after `min(x$versions_end, y$versions_end)`, the
123+
#' observation columns from the less up-to-date archive will be all NAs (i.e.,
124+
#' imagine there was an update immediately after its `versions_end` which
125+
#' revised all observations to be `NA`); `"locf"`: use `max(x$versions_end,
126+
#' y$versions_end)` as the result's `versions_end`, allowing the last version
127+
#' of each observation to be carried forward to extrapolate unavailable
128+
#' versions for the less up-to-date input archive (i.e., imagining that in the
129+
#' less up-to-date archive's data set remained unchanged between its actual
130+
#' `versions_end` and the other archive's `versions_end`); or `"truncate"`:
131+
#' use `min(x$versions_end, y$versions_end)` as the result's `versions_end`,
128132
#' and discard any rows containing update rows for later versions.
129133
#' @param compactify Optional; `TRUE`, `FALSE`, or `NULL`; should the result be
130134
#' compactified? See [`as_epi_archive`] for an explanation of what this means.
@@ -151,7 +155,7 @@ epix_fill_through_version = function(x, fill_versions_end,
151155
#' @importFrom data.table key set
152156
#' @export
153157
epix_merge = function(x, y,
154-
versions_end_conflict = c("stop","na","locf","truncate"),
158+
sync = c("forbid","na","locf","truncate"),
155159
compactify = TRUE) {
156160
if (!inherits(x, "epi_archive")) {
157161
Abort("`x` must be of class `epi_archive`.")
@@ -161,7 +165,7 @@ epix_merge = function(x, y,
161165
Abort("`y` must be of class `epi_archive`.")
162166
}
163167

164-
versions_end_conflict <- rlang::arg_match(versions_end_conflict)
168+
sync <- rlang::arg_match(sync)
165169

166170
if (!identical(x$geo_type, y$geo_type)) {
167171
Abort("`x` and `y` must have the same `$geo_type`")
@@ -192,24 +196,24 @@ epix_merge = function(x, y,
192196
# preprocessing using non-mutating (but potentially aliasing) functions. This
193197
# approach potentially uses more memory, but won't leave behind a
194198
# partially-mutated `x` on failure.
195-
if (versions_end_conflict == "stop") {
199+
if (sync == "forbid") {
196200
if (!identical(x$versions_end, y$versions_end)) {
197201
Abort(paste(
198202
"`x` and `y` were not equally up to date version-wise:",
199203
"`x$versions_end` was not identical to `y$versions_end`;",
200204
"either ensure that `x` and `y` are equally up to date before merging,",
201-
"or specify how to deal with this using `versions_end_conflict`"
202-
), class="epiprocess__epix_merge_unresolved_versions_end_conflict")
205+
"or specify how to deal with this using `sync`"
206+
), class="epiprocess__epix_merge_unresolved_sync")
203207
} else {
204208
new_versions_end = x$versions_end
205209
x_DT = x$DT
206210
y_DT = y$DT
207211
}
208-
} else if (versions_end_conflict %in% c("na", "locf")) {
212+
} else if (sync %in% c("na", "locf")) {
209213
new_versions_end = max(x$versions_end, y$versions_end)
210-
x_DT = epix_fill_through_version(x, new_versions_end, versions_end_conflict)$DT
211-
y_DT = epix_fill_through_version(y, new_versions_end, versions_end_conflict)$DT
212-
} else if (versions_end_conflict == "truncate") {
214+
x_DT = epix_fill_through_version(x, new_versions_end, sync)$DT
215+
y_DT = epix_fill_through_version(y, new_versions_end, sync)$DT
216+
} else if (sync == "truncate") {
213217
new_versions_end = min(x$versions_end, y$versions_end)
214218
x_DT = x$DT[x[["DT"]][["version"]] <= new_versions_end, with=FALSE]
215219
y_DT = y$DT[y[["DT"]][["version"]] <= new_versions_end, with=FALSE]

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-
versions_end_conflict="locf",
35+
sync="locf",
3636
compactify=FALSE)
3737

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

man/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/epix_merge.Rd

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

tests/testthat/test-epix_merge.R

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
test_that("epix_merge requires stops on invalid `y`",{
2+
test_that("epix_merge requires forbids on invalid `y`",{
33
ea = archive_cases_dv_subset$clone()
44
expect_error(epix_merge(ea, data.frame(x=1)))
55
})
@@ -62,7 +62,7 @@ test_that("epix_merge merges and carries forward updates properly", {
6262
expect_identical(xy, xy_expected)
6363
})
6464

65-
test_that('epix_merge stops and warns on metadata and naming issues', {
65+
test_that('epix_merge forbids and warns on metadata and naming issues', {
6666
expect_error(
6767
epix_merge(
6868
as_epi_archive(tibble::tibble(geo_value="tx", time_value=1L, version=1L, x_value=1L)),
@@ -123,16 +123,16 @@ local({
123123
local({
124124
x = as_epi_archive(tibble::tibble(geo_value=1L, time_value=1L, version=1L, x_value=10L))
125125
y = as_epi_archive(tibble::tibble(geo_value=1L, time_value=1L, version=5L, y_value=20L))
126-
print(epix_merge(x,y, versions_end_conflict = "na"))
127-
test_that('epix_merge stops on versions_end_conflict default or "stop"', {
126+
print(epix_merge(x,y, sync = "na"))
127+
test_that('epix_merge forbids on sync default or "forbid"', {
128128
expect_error(epix_merge(x,y),
129-
class="epiprocess__epix_merge_unresolved_versions_end_conflict")
130-
expect_error(epix_merge(x,y, versions_end_conflict = "stop"),
131-
class="epiprocess__epix_merge_unresolved_versions_end_conflict")
129+
class="epiprocess__epix_merge_unresolved_sync")
130+
expect_error(epix_merge(x,y, sync = "forbid"),
131+
class="epiprocess__epix_merge_unresolved_sync")
132132
})
133-
test_that('epix_merge versions_end_conflict="na" works', {
133+
test_that('epix_merge sync="na" works', {
134134
expect_equal(
135-
epix_merge(x,y, versions_end_conflict = "na"),
135+
epix_merge(x,y, sync = "na"),
136136
as_epi_archive(tibble::tribble(
137137
~geo_value, ~time_value, ~version, ~x_value, ~y_value,
138138
1L, 1L, 1L, 10L, NA_integer_, # x updated, y not observed yet
@@ -141,9 +141,9 @@ local({
141141
), clobberable_versions_start=1L)
142142
)
143143
})
144-
test_that('epix_merge versions_end_conflict="locf" works', {
144+
test_that('epix_merge sync="locf" works', {
145145
expect_equal(
146-
epix_merge(x,y, versions_end_conflict = "locf"),
146+
epix_merge(x,y, sync = "locf"),
147147
as_epi_archive(tibble::tribble(
148148
~geo_value, ~time_value, ~version, ~x_value, ~y_value,
149149
1L, 1L, 1L, 10L, NA_integer_, # x updated, y not observed yet
@@ -157,36 +157,36 @@ local({
157157
~geo_value, ~time_value, ~version, ~x_value, ~y_value,
158158
1L, 1L, 1L, 10L, 20L, # x updated, y not observed yet
159159
))
160-
test_that('epix_merge versions_end_conflict="stop" on no-conflict works', {
160+
test_that('epix_merge sync="forbid" on no-conflict works', {
161161
expect_equal(
162-
epix_merge(x_no_conflict, y_no_conflict, versions_end_conflict = "stop"),
162+
epix_merge(x_no_conflict, y_no_conflict, sync = "forbid"),
163163
xy_no_conflict_expected
164164
)
165165
})
166-
test_that('epix_merge versions_end_conflict="na" on no-conflict works', {
166+
test_that('epix_merge sync="na" on no-conflict works', {
167167
# This test is the main reason for these no-conflict tests. We want to make
168168
# sure that we don't add an unnecessary NA-ing-out version beyond a common
169169
# versions_end.
170170
expect_equal(
171-
epix_merge(x_no_conflict, y_no_conflict, versions_end_conflict = "na"),
171+
epix_merge(x_no_conflict, y_no_conflict, sync = "na"),
172172
xy_no_conflict_expected
173173
)
174174
})
175-
test_that('epix_merge versions_end_conflict="locf" on no-conflict works', {
175+
test_that('epix_merge sync="locf" on no-conflict works', {
176176
expect_equal(
177-
epix_merge(x_no_conflict, y_no_conflict, versions_end_conflict = "locf"),
177+
epix_merge(x_no_conflict, y_no_conflict, sync = "locf"),
178178
xy_no_conflict_expected
179179
)
180180
})
181181
})
182182

183183

184-
test_that('epix_merge versions_end_conflict="na" balks if do not know next_after', {
184+
test_that('epix_merge sync="na" balks if do not know next_after', {
185185
expect_error(
186186
epix_merge(
187187
as_epi_archive(tibble::tibble(geo_value=1L, time_value=1L, version=as.POSIXct(as.Date("2020-01-01")), x_value=10L)),
188188
as_epi_archive(tibble::tibble(geo_value=1L, time_value=1L, version=as.POSIXct(as.Date("2020-01-02")), y_value=20L)),
189-
versions_end_conflict = "na"
189+
sync = "na"
190190
),
191191
regexp = "no applicable method.*next_after"
192192
)

vignettes/archive.Rmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ When merging archives, unless the archives have identical data release patterns,
244244
been released)
245245
- to represent the "value" of an observation that has no recorded versions at
246246
all (in the same sort of situation)
247-
- if requested via `versions_end_conflict="na"`, to represent potential
248-
update data that we do not yet have access to (e.g., due to one of the
249-
archives being out of sync).
247+
- if requested via `sync="na"`, to represent potential update data that we do
248+
not yet have access to (e.g., due to encountering issues while attempting to
249+
download the currently available version data for one of the archives, but not
250+
the other).
250251

251252
```{r, message = FALSE, warning = FALSE,eval=FALSE}
252253
y <- covidcast(

0 commit comments

Comments
 (0)