Floating point issue causing `combine_supp()` not to merge
Closed this issue · 0 comments
billdenney commented
Related to #31
I was trying to track down the reason that a merge was failing for me, and it appears to be due to a floating point imprecision issue. I have a value of 24.04 that is loading from an .xpt file as a value subtly above 24.04 while R's as.numeric("24.04")
gives a value subtly below 24.04.
I get the same value if I:
- round the value from the .xpt file to 2 decimal places, or
- run it through
as.numeric(as.character(x))
> sprintf("%0.32f", primary_error_reprex$VISITNUM)
[1] "24.04000000000000625277607468888164"
> sprintf("%0.32f", 24.04)
[1] "24.03999999999999914734871708787978"
> sprintf("%0.32f", round(primary_error_reprex$VISITNUM, 2))
[1] "24.03999999999999914734871708787978"
> sprintf("%0.32f", as.numeric(as.character(primary_error_reprex$VISITNUM)))
[1] "24.03999999999999914734871708787978"
With this file (issue-33.zip), the reprex is below. (The file is uploaded as a .zip file because I need precision in the number, and I can't upload a .Rdata file to GitHub directly.)
library(metatools)
load(file=unz(description="issue-33.zip", filename="issue-33.Rdata"))
combine_supp(primary_error_reprex, supp_error_reprex)
#> Error: 1 rows with IDVAR VISITNUM did not merge from the supp data to the main data
Created on 2022-06-14 by the reprex package (v2.0.1)