@@ -118,6 +118,8 @@ approx_equal0 <- function(vec1, vec2, abs_tol, na_equal, inds1 = NULL, inds2 = N
118
118
# ' `compactify_abs_tol`.
119
119
# ' @param compactify_abs_tol compactification tolerance; see `apply_compactify`
120
120
# ' @return a tibble in compact "update" (diff) format
121
+ # '
122
+ # ' @keywords internal
121
123
tbl_diff2 <- function (earlier_snapshot , later_tbl ,
122
124
ukey_names ,
123
125
later_format = c(" snapshot" , " update" ),
@@ -152,7 +154,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
152
154
153
155
# More input validation:
154
156
if (! identical(tbl_names , names(later_tbl ))) {
155
- # XXX is this check actually necessary?
156
157
cli_abort(c(" `earlier_snapshot` and `later_tbl` should have identical column
157
158
names and ordering." ,
158
159
" *" = " `earlier_snapshot` colnames: {format_chr_deparse(tbl_names)}" ,
@@ -200,7 +201,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
200
201
combined_compactify_away [combined_ukey_is_repeat ] <-
201
202
approx_equal0(combined_vals ,
202
203
combined_vals ,
203
- # TODO move inds closer to vals to not be as confusing?
204
204
abs_tol = compactify_abs_tol ,
205
205
na_equal = TRUE ,
206
206
inds1 = combined_ukey_is_repeat ,
@@ -230,17 +230,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
230
230
combined_tbl
231
231
}
232
232
233
- epi_diff2 <- function (earlier_snapshot , later_edf ,
234
- later_format = c(" snapshot" , " update" ),
235
- compactify_abs_tol = 0 ) {
236
- ukey_names <- key_colnames(later_edf )
237
- dplyr_reconstruct(tbl_diff2(as_tibble(earlier_snapshot ), as_tibble(later_edf ), ukey_names , later_format , compactify_abs_tol ), later_edf )
238
- }
239
-
240
- # XXX vs. tbl_patch_apply?
241
-
242
-
243
-
244
233
# ' Apply an update (e.g., from `tbl_diff2`) to a snapshot
245
234
# '
246
235
# ' @param snapshot tibble or `NULL`; entire data set as of some version, or
@@ -252,14 +241,12 @@ epi_diff2 <- function(earlier_snapshot, later_edf,
252
241
# ' for `snapshot` and for `update`. Uniqueness is unchecked; if you don't have
253
242
# ' this guaranteed, see [`check_ukey_unique()`].
254
243
# ' @return tibble; snapshot of the data set with the update applied.
244
+ # '
245
+ # ' @keywords internal
255
246
tbl_patch <- function (snapshot , update , ukey_names ) {
256
247
# Most input validation. This is a small function so use faster validation
257
248
# variants:
258
249
if (! is_tibble(update )) {
259
- # XXX debating about whether to have a specialized class for updates/diffs.
260
- # Seems nice for type-based reasoning and might remove some args from
261
- # interfaces, but would require constructor/converter functions for that
262
- # type.
263
250
cli_abort(" `update` must be a tibble" )
264
251
}
265
252
if (is.null(snapshot )) {
@@ -271,19 +258,19 @@ tbl_patch <- function(snapshot, update, ukey_names) {
271
258
if (! is.character(ukey_names ) || ! all(ukey_names %in% names(snapshot ))) {
272
259
cli_abort(" `ukey_names` must be a subset of column names" )
273
260
}
261
+ if (! identical(names(snapshot ), names(update ))) {
262
+ cli_abort(c(" `snapshot` and `update` should have identical column
263
+ names and ordering." ,
264
+ " *" = " `snapshot` colnames: {format_chr_deparse(tbl_names)}" ,
265
+ " *" = " `update` colnames: {format_chr_deparse(names(update))}"
266
+ ))
267
+ }
274
268
275
269
result_tbl <- vec_rbind(update , snapshot )
276
270
277
271
dup_ids <- vec_duplicate_id(result_tbl [ukey_names ])
278
272
not_overwritten <- dup_ids == vec_seq_along(result_tbl )
279
273
result_tbl <- result_tbl [not_overwritten , ]
280
274
281
- # # result_tbl <- arrange_canonical(result_tbl)
282
-
283
275
result_tbl
284
276
}
285
-
286
- epi_patch <- function (snapshot , update ) {
287
- ukey_names <- key_colnames(update )
288
- dplyr_reconstruct(tbl_patch(as_tibble(snapshot ), as_tibble(update ), ukey_names ), update )
289
- }
0 commit comments