-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring matchTolerance #706
Refactoring matchTolerance #706
Conversation
Code Coverage Summary
Diff against main
Results for commit: c36809b Minimum allowed coverage is ♻️ This comment has been updated with latest results |
….com:Roche/crmPack into 705-replace-matchtolerance-with-assert_equal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Puzzled-Face , nice, please see comments below
R/checkmate.R
Outdated
#' | ||
#' @note If elements in `...` are not all of the same length, `FALSE` is returned. | ||
#' | ||
#' @return TRUE if all element-by-element differences are less than `tolerance` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#' @return TRUE if all element-by-element differences are less than `tolerance` | |
#' @return `TRUE` if all element-by-element differences are less than `tolerance` |
check_equal <- function(..., tol = sqrt(.Machine$double.eps)) { | ||
dot_args <- list(...) | ||
|
||
sapply(dot_args, assert_numeric) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use vapply
everywhere here (because it is safer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use
vapply
everywhere here (because it is safer)
vapply
is new to me. Not sure I agree here.
The potential problem is vapply
's FUN.VALUE
argument. From the online doc: "all values of FUN [should be] compatible with the FUN.VALUE, in that they must have the same length and type".
The problem is that we don't know:
- How many entries are in
...
- The length of each entry in
...
and, in addition,
assert_numeric
returns an object of the same type as its first argument (or throws an error)
I think we could work all that out, but it would add considerably to the complexity of the function.
#' assert_equal(1:2, 1:2) # no error | ||
#' assert_equal(0.01, 0.02, tol = 0.05) # no error | ||
# nolint start | ||
assert_equal <- function(..., tol = sqrt(.Machine$double.eps), .var.name = vname(x), add = NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use makeAssertionFunction
or add comment why that would not work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use
makeAssertionFunction
or add comment why that would not work
assert_equal <- makeAssertionFunction(check_equal)
fails with error "Error in checkmate::makeAssertion(..., res, .var.name, add)
: unused argument (add)". I think this is because of the use of ...
in check_equal
.
See #683 and #705 for details