Skip to content

Commit 980e9b7

Browse files
committed
docs(approx_equal): roxygen2 + comment on inconsistencies/bugs
1 parent d8ac7db commit 980e9b7

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

R/patch.R

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
#' Test two vctrs vectors for equality with some tolerance in some cases
2+
#'
3+
#' @param vec1,vec2 vctrs vectors (includes data frames)
4+
#' @param abs_tol tolerance; will be used for bare numeric `vec1`, `vec2`, or
5+
#' any such columns within `vec1`, `vec2` if they are data frames
6+
#' @param na_equal should `NA`s be considered equal to each other? (In
7+
#' epiprocess, we usually want this to be `TRUE`, but that doesn't match the
8+
#' [`vctrs::vec_equal()`] default, so this is mandatory.)
9+
#' @param .ptype as in [`vctrs::vec_equal()`]
10+
#' @param inds1,inds2 optional (row) indices into vec1 and vec2; output should
11+
#' be consistent with `vec_slice`-ing to these indices beforehand, but can
12+
#' give faster computation if `vec1` and `vec2` are data frames.
13+
#'
14+
#' @return logical vector; no nonmissing entries if `na_equal = TRUE`. Behavior
15+
#' may differ from `vec_equal` with non-`NA` `NaN`s involved.
116
approx_equal <- function(vec1, vec2, abs_tol, na_equal, .ptype = NULL, inds1 = NULL, inds2 = NULL) {
217
# Recycle inds if provided; vecs if not:
318
common_size <- vec_size_common(
@@ -30,6 +45,9 @@ approx_equal0 <- function(vec1, vec2, abs_tol, na_equal, inds1 = NULL, inds2 = N
3045
!is.na(vec1) & !is.na(vec2),
3146
abs(vec1 - vec2) <= abs_tol,
3247
if (na_equal) is.na(vec1) & is.na(vec2) else FALSE
48+
# XXX ^ inconsistent with vec_equal treatment: NA vs. NaN comparison
49+
# behavior with na_equal = TRUE is different; plus output with na_equal =
50+
# FALSE on two NAs is different
3351
)
3452
# `fifelse` inherits any unrecognized attributes; drop them instead:
3553
attributes(res) <- NULL
@@ -45,7 +63,7 @@ approx_equal0 <- function(vec1, vec2, abs_tol, na_equal, inds1 = NULL, inds2 = N
4563
}))
4664
}
4765
} else {
48-
# No special handling for any other types/situations. Makes sense for
66+
# XXX No special handling for any other types/situations. Makes sense for
4967
# unclassed atomic things; bare lists and certain vctrs classes might want
5068
# recursion / specialization, though.
5169
if (!is.null(inds1)) {

man/approx_equal.Rd

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

0 commit comments

Comments
 (0)