@@ -118,6 +118,8 @@ approx_equal0 <- function(vec1, vec2, abs_tol, na_equal, inds1 = NULL, inds2 = N
118118# ' `compactify_abs_tol`.
119119# ' @param compactify_abs_tol compactification tolerance; see `apply_compactify`
120120# ' @return a tibble in compact "update" (diff) format
121+ # '
122+ # ' @keywords internal
121123tbl_diff2 <- function (earlier_snapshot , later_tbl ,
122124 ukey_names ,
123125 later_format = c(" snapshot" , " update" ),
@@ -152,7 +154,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
152154
153155 # More input validation:
154156 if (! identical(tbl_names , names(later_tbl ))) {
155- # XXX is this check actually necessary?
156157 cli_abort(c(" `earlier_snapshot` and `later_tbl` should have identical column
157158 names and ordering." ,
158159 " *" = " `earlier_snapshot` colnames: {format_chr_deparse(tbl_names)}" ,
@@ -200,7 +201,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
200201 combined_compactify_away [combined_ukey_is_repeat ] <-
201202 approx_equal0(combined_vals ,
202203 combined_vals ,
203- # TODO move inds closer to vals to not be as confusing?
204204 abs_tol = compactify_abs_tol ,
205205 na_equal = TRUE ,
206206 inds1 = combined_ukey_is_repeat ,
@@ -230,17 +230,6 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
230230 combined_tbl
231231}
232232
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-
244233# ' Apply an update (e.g., from `tbl_diff2`) to a snapshot
245234# '
246235# ' @param snapshot tibble or `NULL`; entire data set as of some version, or
@@ -252,14 +241,12 @@ epi_diff2 <- function(earlier_snapshot, later_edf,
252241# ' for `snapshot` and for `update`. Uniqueness is unchecked; if you don't have
253242# ' this guaranteed, see [`check_ukey_unique()`].
254243# ' @return tibble; snapshot of the data set with the update applied.
244+ # '
245+ # ' @keywords internal
255246tbl_patch <- function (snapshot , update , ukey_names ) {
256247 # Most input validation. This is a small function so use faster validation
257248 # variants:
258249 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.
263250 cli_abort(" `update` must be a tibble" )
264251 }
265252 if (is.null(snapshot )) {
@@ -271,19 +258,19 @@ tbl_patch <- function(snapshot, update, ukey_names) {
271258 if (! is.character(ukey_names ) || ! all(ukey_names %in% names(snapshot ))) {
272259 cli_abort(" `ukey_names` must be a subset of column names" )
273260 }
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+ }
274268
275269 result_tbl <- vec_rbind(update , snapshot )
276270
277271 dup_ids <- vec_duplicate_id(result_tbl [ukey_names ])
278272 not_overwritten <- dup_ids == vec_seq_along(result_tbl )
279273 result_tbl <- result_tbl [not_overwritten , ]
280274
281- # # result_tbl <- arrange_canonical(result_tbl)
282-
283275 result_tbl
284276}
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