Closed iaugusty closed 9 months ago
rather than signif, round should be used, round(x[2],10^25) == 1. signif(507/524,10^25) also results in 1
better option might be to use all.equal(x[2],1)
I tried all your options on your code and I still get 82 "fmt not as expected"
sample <- 1000
xx <- data.frame(Ncol=1:sample)
xx <- xx %>%
rowwise() %>%
mutate(count=Ncol) %>%
mutate(pct = count*(1/Ncol)) %>%
mutate(fmt_tern = format_count_fraction_fixed_dp(c(count,pct))) %>%
**mutate(check = all.equal(pct,1)) %>%**
mutate(fmtissue = ifelse(!check,"fmt not as expected","fmt as expected"))
table(xx$fmtissue)
.is_equal_float <- function(x, y) {
checkmate::assert_number(x)
checkmate::assert_number(y)
# Define a tolerance
tolerance <- .Machine$double.eps
# Check if x is close enough to y
abs(x - y) < tolerance
}
This is better as all.equal
produces a string in case of false
What happened?
A bug happened! format_count_fraction_fixed_dp(x), when x = c(denom,denom*(1/denom)) is not always denom (100%). This is as the check on the fraction : x[2] == 1 is not always true.
Replacing the check with signif(x[2],10^25) == 1, would resolve the bug.
sessionInfo()
Relevant log output
No response
Code of Conduct
Contribution Guidelines
Security Policy