Skip to content

Commit 1978bab

Browse files
committed
fix(approx_equal): on bare numeric matrices
1 parent a10a743 commit 1978bab

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

R/patch.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ approx_equal0 <- function(vec1, vec2, abs_tol, na_equal, inds1 = NULL, inds2 = N
3737
if (is_bare_numeric(vec1) && abs_tol != 0) {
3838
# perf: since we're working with bare numerics and logicals: we can use `[`
3939
# and `fifelse`. Matching vec_equal, we ignore names and other attributes.
40-
41-
# FIXME matrices can make their way in here though...
42-
if (!is.null(inds1)) vec1 <- vec1[inds1]
43-
if (!is.null(inds2)) vec2 <- vec2[inds2]
40+
if (!is.null(inds1)) vec1 <- vec_slice(vec1, inds1)
41+
if (!is.null(inds2)) vec2 <- vec_slice(vec2, inds2)
4442
res <- fifelse(
4543
!is.na(vec1) & !is.na(vec2),
4644
abs(vec1 - vec2) <= abs_tol,
4745
if (na_equal) is.na(vec1) & is.na(vec2) else NA
4846
# XXX ^ inconsistent with vec_equal treatment: NA vs. NaN comparison
4947
# behavior with na_equal = TRUE is different
5048
)
49+
if (!is.null(dim(vec1))) {
50+
dim(res) <- dim(vec1)
51+
res <- rowSums(res) == ncol(res)
52+
}
5153
# `fifelse` inherits any unrecognized attributes; drop them instead:
5254
attributes(res) <- NULL
5355
return(res)

0 commit comments

Comments
 (0)