Skip to content
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

Merged
merged 7 commits into from
Oct 16, 2023

Conversation

Puzzled-Face
Copy link
Collaborator

See #683 and #705 for details

@Puzzled-Face Puzzled-Face linked an issue Oct 13, 2023 that may be closed by this pull request
@Puzzled-Face Puzzled-Face enabled auto-merge (squash) October 13, 2023 09:16
@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2023

badge

Code Coverage Summary

Filename                    Stmts    Miss  Cover    Missing
------------------------  -------  ------  -------  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
R/checkmate.R                  73       1  98.63%   72
R/crmPack-package.R             4       0  100.00%
R/Data-class.R                 92       4  95.65%   467-468, 474-479
R/Data-methods.R              203       0  100.00%
R/Data-validity.R             144       1  99.31%   21
R/Design-class.R               75       0  100.00%
R/Design-methods.R           2763    2328  15.74%   111, 136-139, 147-158, 162-181, 193-197, 203-216, 392-969, 1034-1375, 1426, 1616, 1787-4592, 4711
R/Design-validity.R            20       0  100.00%
R/fromQuantiles.R             178      69  61.24%   237-378
R/helpers_covr.R               23       0  100.00%
R/helpers_data.R               84       1  98.81%   139
R/helpers_design.R             75      36  52.00%   22, 77-129
R/helpers_jags.R               77       0  100.00%
R/helpers_model.R              78       4  94.87%   38, 89-90, 139
R/helpers_rules.R             447       0  100.00%
R/helpers_simulations.R        18       0  100.00%
R/helpers.R                   229      65  71.62%   107-127, 140, 153-167, 203-323, 358-372
R/logger.R                     11       0  100.00%
R/mcmc.R                      287      18  93.73%   90-95, 374-375, 385, 387-388, 391-394, 577-578, 667, 673, 731
R/McmcOptions-class.R          18       0  100.00%
R/McmcOptions-methods.R         8       1  87.50%   43
R/McmcOptions-validity.R       42       0  100.00%
R/Model-class.R               962     155  83.89%   135-137, 205-207, 211-213, 272-274, 346-348, 352-354, 433-435, 502-504, 566-570, 573-576, 679-682, 686-687, 802-806, 926-928, 932-940, 1085-1087, 1092-1095, 1099-1102, 1218-1222, 1224-1227, 1231-1234, 1237, 1398-1408, 1413-1419, 1574-1577, 1583-1590, 1747, 1756, 1765, 1774, 1783-1788, 1924, 1933, 1942, 1950-1952, 2693-2722, 2726-2732, 2739-2743, 2748, 2855-2868, 2894, 2990-2992, 2996, 3089-3091, 3095, 3164-3176, 3194
R/Model-methods.R             376      34  90.96%   78, 155, 208, 675-720, 1039-1048
R/Model-validity.R            435       8  98.16%   430-433, 442-445
R/ModelParams-class.R          13       0  100.00%
R/ModelParams-validity.R       21       0  100.00%
R/Rules-class.R               416       2  99.52%   3102, 3169
R/Rules-methods.R            1429     164  88.52%   741, 744, 887, 890, 893, 1008, 1011, 1014, 1134-1137, 1171, 1274-1277, 1312, 2475-2483, 2507-2514, 3017-3260
R/Rules-validity.R            418       0  100.00%
R/Samples-class.R               1       0  100.00%
R/Samples-methods.R          1104      45  95.92%   406-416, 644, 1358-1393, 1616, 1629, 1794, 2124-2129
R/Samples-validity.R           10       0  100.00%
R/Simulations-class.R          51      32  37.25%   408-727
R/Simulations-methods.R      1604    1460  8.98%    65-350, 406, 416-435, 448-453, 500-509, 675-2944
R/Simulations-validity.R       75      75  0.00%    20-168
R/utils.R                       6       0  100.00%
TOTAL                       11870    4503  62.06%

Diff against main

Filename                    Stmts    Miss  Cover
------------------------  -------  ------  --------
R/checkmate.R                 +24      +1  -1.37%
R/Data-class.R                 +1       0  +0.05%
R/Design-methods.R            +29     +18  +0.24%
R/helpers_simulations.R       +18       0  +100.00%
R/helpers.R                   -15     -15  +4.40%
R/Simulations-class.R          +1       0  +1.25%
R/Simulations-methods.R        +7      +6  +0.02%
R/Simulations-validity.R      +75     +75  +100.00%
TOTAL                        +140     +85  -0.27%

Results for commit: c36809b

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions
Copy link
Contributor

github-actions bot commented Oct 13, 2023

Unit Tests Summary

       1 files       37 suites   3m 27s ⏱️
1 178 tests 1 048 ✔️ 130 💤 0
6 211 runs  6 046 ✔️ 165 💤 0

Results for commit c36809b.

♻️ This comment has been updated with latest results.

@danielinteractive danielinteractive self-assigned this Oct 14, 2023
Copy link
Collaborator

@danielinteractive danielinteractive left a 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 Show resolved Hide resolved
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`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' @return TRUE if all element-by-element differences are less than `tolerance`
#' @return `TRUE` if all element-by-element differences are less than `tolerance`

R/checkmate.R Show resolved Hide resolved
check_equal <- function(..., tol = sqrt(.Machine$double.eps)) {
dot_args <- list(...)

sapply(dot_args, assert_numeric)
Copy link
Collaborator

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)

Copy link
Collaborator Author

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:

  1. How many entries are in ...
  2. The length of each entry in ...

and, in addition,

  1. 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.

R/checkmate.R Outdated Show resolved Hide resolved
R/checkmate.R Outdated Show resolved Hide resolved
R/checkmate.R Outdated Show resolved Hide resolved
#' 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) {
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

R/checkmate.R Show resolved Hide resolved
tests/testthat/test-checkmate.R Outdated Show resolved Hide resolved
@Puzzled-Face Puzzled-Face merged commit 6e551ae into main Oct 16, 2023
21 checks passed
@Puzzled-Face Puzzled-Face deleted the 705-replace-matchtolerance-with-assert_equal branch October 16, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace matchTolerance with assert_equal
2 participants