Skip to content

Commit 7c3d243

Browse files
committed
Rename approx_equal -> vec_approx_equal
1 parent 84c9db0 commit 7c3d243

6 files changed

+35
-37
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ S3method(ungroup,epi_df)
5858
S3method(ungroup,grouped_epi_archive)
5959
S3method(unnest,epi_df)
6060
export("%>%")
61-
export(approx_equal)
6261
export(arrange)
6362
export(arrange_canonical)
6463
export(as_epi_archive)
@@ -105,6 +104,7 @@ export(time_column_names)
105104
export(ungroup)
106105
export(unnest)
107106
export(validate_epi_archive)
107+
export(vec_approx_equal)
108108
export(version_column_names)
109109
import(epidatasets)
110110
importFrom(checkmate,anyInfinite)

R/archive.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ update_is_locf <- function(arranged_updates_df, ukey_names, abs_tol) {
468468
inds2 <- 1L:(n_updates - 1L)
469469
c(
470470
FALSE, # first observation is not LOCF
471-
approx_equal0(ekts_tbl,
471+
vec_approx_equal0(ekts_tbl,
472472
inds1 = inds1, ekts_tbl, inds2 = inds2,
473473
# check ekt (key) cols with 0 tolerance:
474474
na_equal = TRUE, abs_tol = 0
475475
) &
476-
approx_equal0(vals_tbl,
476+
vec_approx_equal0(vals_tbl,
477477
inds1 = inds1, vals_tbl, inds2 = inds2,
478478
na_equal = TRUE, abs_tol = abs_tol
479479
)

R/patch.R

+13-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' @examples
2828
#'
2929
#' # On numeric vectors:
30-
#' approx_equal(
30+
#' vec_approx_equal(
3131
#' c(1, 2, 3, NA),
3232
#' c(1, 2 + 1e-10, NA, NA),
3333
#' na_equal = TRUE,
@@ -49,19 +49,19 @@
4949
#' tbl2$c$c1[[4]] <- tbl1$c$c1[[4]] + 1e-10
5050
#' tbl2$d[[5, 2]] <- tbl1$d[[5, 2]] + 1e-10
5151
#' vctrs::vec_equal(tbl1, tbl2, na_equal = TRUE)
52-
#' approx_equal(tbl1, tbl2, na_equal = TRUE, abs_tol = 1e-12)
53-
#' approx_equal(tbl1, tbl2, na_equal = TRUE, abs_tol = 1e-8)
52+
#' vec_approx_equal(tbl1, tbl2, na_equal = TRUE, abs_tol = 1e-12)
53+
#' vec_approx_equal(tbl1, tbl2, na_equal = TRUE, abs_tol = 1e-8)
5454
#'
5555
#'
5656
#'
5757
#'
5858
#'
5959
#' # Type comparison within lists is stricter, matching vctrs:
6060
#' vctrs::vec_equal(list(1:2), list(as.numeric(1:2)))
61-
#' approx_equal(list(1:2), list(as.numeric(1:2)), FALSE, abs_tol = 0)
61+
#' vec_approx_equal(list(1:2), list(as.numeric(1:2)), FALSE, abs_tol = 0)
6262
#'
6363
#' @export
64-
approx_equal <- function(vec1, vec2, na_equal, .ptype = NULL, ..., abs_tol, inds1 = NULL, inds2 = NULL) {
64+
vec_approx_equal <- function(vec1, vec2, na_equal, .ptype = NULL, ..., abs_tol, inds1 = NULL, inds2 = NULL) {
6565
if (!obj_is_vector(vec1)) cli_abort("`vec1` must be recognized by vctrs as a vector")
6666
if (!obj_is_vector(vec2)) cli_abort("`vec2` must be recognized by vctrs as a vector")
6767
# Leave vec size checking to vctrs recycling ops.
@@ -99,13 +99,13 @@ approx_equal <- function(vec1, vec2, na_equal, .ptype = NULL, ..., abs_tol, inds
9999
inds2 <- vec_recycle(inds2, common_size)
100100
}
101101
vecs <- vec_cast_common(vec1, vec2, .to = .ptype)
102-
approx_equal0(vecs[[1]], vecs[[2]], na_equal, abs_tol, inds1, inds2)
102+
vec_approx_equal0(vecs[[1]], vecs[[2]], na_equal, abs_tol, inds1, inds2)
103103
}
104104

105-
#' Helper for [`approx_equal`] for vecs guaranteed to have the same ptype and size
105+
#' Helper for [`vec_approx_equal`] for vecs guaranteed to have the same ptype and size
106106
#'
107107
#' @keywords internal
108-
approx_equal0 <- function(vec1, vec2, na_equal, abs_tol, inds1 = NULL, inds2 = NULL) {
108+
vec_approx_equal0 <- function(vec1, vec2, na_equal, abs_tol, inds1 = NULL, inds2 = NULL) {
109109
if (is_bare_numeric(vec1) && abs_tol != 0) {
110110
# perf: since we're working with bare numerics and logicals: we can use `[`
111111
# and `fifelse`. Matching vec_equal, we ignore names and other attributes.
@@ -132,7 +132,7 @@ approx_equal0 <- function(vec1, vec2, na_equal, abs_tol, inds1 = NULL, inds2 = N
132132
rep(TRUE, nrow(vec1))
133133
} else {
134134
Reduce(`&`, lapply(seq_len(ncol(vec1)), function(col_i) {
135-
approx_equal0(vec1[[col_i]], vec2[[col_i]], na_equal, abs_tol, inds1, inds2)
135+
vec_approx_equal0(vec1[[col_i]], vec2[[col_i]], na_equal, abs_tol, inds1, inds2)
136136
}))
137137
}
138138
} else if (is_bare_list(vec1)) {
@@ -144,14 +144,14 @@ approx_equal0 <- function(vec1, vec2, na_equal, abs_tol, inds1 = NULL, inds2 = N
144144
# consistently inconsistent, we avoid dispatching to vec_equal for bare
145145
# lists even with abs_tol = 0:
146146
identical(vec_ptype(entry1), vec_ptype(entry2)) &&
147-
all(approx_equal0(entry1, entry2, na_equal, abs_tol))
147+
all(vec_approx_equal0(entry1, entry2, na_equal, abs_tol))
148148
}, logical(1L))
149149
} else {
150150
# XXX No special handling for any other types/situations. Makes sense for
151151
# unclassed atomic things; custom classes (e.g., distributions) might want
152-
# recursion / specialization, though. approx_equal0 should probably be an S3
152+
# recursion / specialization, though. vec_approx_equal0 should probably be an S3
153153
# method. Also, abs_tol == 0 --> vec_equal logic should maybe be either be
154-
# hoisted to approx_equal or we should manually recurse on data frames even
154+
# hoisted to vec_approx_equal or we should manually recurse on data frames even
155155
# with abs_tol = 0 when that's faster (might depend on presence of inds*),
156156
# after some inconsistencies are ironed out.
157157
if (!is.null(inds1)) {
@@ -265,7 +265,7 @@ tbl_diff2 <- function(earlier_snapshot, later_tbl,
265265
# Which rows from combined are in case 3.?
266266
combined_compactify_away <- rep(FALSE, combined_n)
267267
combined_compactify_away[combined_ukey_is_repeat] <-
268-
approx_equal0(combined_vals,
268+
vec_approx_equal0(combined_vals,
269269
combined_vals,
270270
na_equal = TRUE,
271271
abs_tol = compactify_abs_tol,
@@ -340,5 +340,3 @@ tbl_patch <- function(snapshot, update, ukey_names) {
340340

341341
result_tbl
342342
}
343-
344-
# TODO rename approx_equal to vec_approx_equal

man/approx_equal0.Rd

-12
This file was deleted.

man/approx_equal.Rd man/vec_approx_equal.Rd

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/vec_approx_equal0.Rd

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)