- Notifications
You must be signed in to change notification settings - Fork22
Open
Description
library(waldo)dt<- as.POSIXct("2016-07-18 16:06:00",tz="UTC")compare(dt,dt+5)#> `old`: "2016-07-18 16:06:00"#> `new`: "2016-07-18 16:06:05"compare(1468857960,1468857965)#> `old`: 1468857960#> `new`: 1468857965(tol<-testthat::testthat_tolerance())#> [1] 1.490116e-08compare(dt,dt+5,tolerance=tol)#> ✓ No differencescompare(1468857960,1468857965,tolerance=tol)#> ✓ No differences
Created on 2022-03-12 by thereprex package (v2.0.1)
Compared withall.equal() which has different behaviour for POSIXct:
library(waldo)dt<- as.POSIXct("2016-07-18 16:06:00",tz="UTC")all.equal(dt,dt+5)#> [1] "Mean absolute difference: 5"all.equal(1468857960,1468857965)#> [1] TRUE
Created on 2022-03-12 by thereprex package (v2.0.1)
I don't think the behaviour is correct in either case: the purpose of tolerance is to ignore minor differences that arise due to floating point error, not to ignore differences in integers that can be exactly represented in floating point.