cryptic error when `expect_equal(x, y, tolerance = -Inf)`
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- r
- Domain
- testing-qa
Research direction
Start by reproducing the provided MRE through testthat::expect_equal(), then trace the tolerance handling through testthat:::waldo_compare() and waldo::compare(), as shown in the backtrace. Identify where tolerance = -Inf becomes NaN and add regression coverage that verifies the resulting diagnostic is informative rather than cryptic.
Written by the indexing model from the issue text.
Description
Hi,
This is not really a critical bug...
I was writing tests and hoped expect_equal(actual, expected, tolerance = -Inf) would use the "lowest possible tolerance". I did not even expect it to work. I am reporting because of the cryptic error message.
MRE:
# Success
test_that("1 = 1 with minimum tolerance", {
expect_equal(1,1,tolerance = -Inf)
})
# Cryptic Error message
test_that("1 = 1.1 with minimum tolerance", {
expect_equal(1,1.1,tolerance = -Inf) # does not work
})
# Success
test_that("1 = 1.1 with maximum tolerance", {
expect_equal(1,1.1,tolerance = Inf)
})
error message
── Warning: 1 = 1.1 with minimum tolerance ───────────────────────────────────
NaNs produced
Backtrace:
▆
1. └─testthat::expect_equal(1, 1.1, tolerance = -Inf)
2. └─testthat:::expect_waldo_equal_(msg, act, exp, info, ..., tolerance = tolerance)
3. └─testthat:::waldo_compare(...)
4. └─waldo::compare(x, y, ..., x_arg = x_arg, y_arg = y_arg)
5. └─waldo:::compare_structure(x, y, paths = c(x_arg, y_arg), opts = opts)
6. └─waldo:::compare_vector(x, y, paths = paths, opts = opts)
7. └─waldo:::compare_numeric(...)
8. └─waldo:::min_digits(x, y, tolerance)
9. └─waldo:::digits(tolerance)
> packageVersion("testthat")
[1] ‘3.3.2’
> packageVersion("waldo")
[1] ‘0.6.2’
> version
_
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 6.1
year 2026
month 06
day 24
svn rev 90187
language R
version.string R version 4.6.1 (2026-06-24)
nickname Happy Hop
- Dominant language
- R
- Stars
- 939
- Forks
- 346
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from r-lib/testthat
-
Documentation for expect_error argument 'regexp' says it accepts a character vector but it does not Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 66/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·