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

Fix testing for NA_REAL (fixes #258) #259

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Title: Fast and Versatile Argument Checks
Description: Tests and assertions to perform frequent argument checks. A
substantial part of the package was written in C to minimize any worries
about execution time overhead.
Version: 2.3.1
Version: 2.3.2
Authors@R: c(
person("Michel", "Lang", NULL, "[email protected]",
role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 2.3.1
* Fixed a sortedness check bug for numeric vectors with NAs (#258).

# Version 2.3.1
* Fixed a sprintf format string for long integers.

Expand Down
2 changes: 1 addition & 1 deletion src/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ R_xlen_t attribute_hidden as_length(SEXP x, const char *vname) {
return (R_xlen_t) xi;
case REALSXP:;
double xr = REAL_RO(x)[0];
if (xr == NA_REAL)
if (ISNA(xr))
error("Argument '%s' may not be missing", vname);
if (xr < 0)
error("Argument '%s' must be >= 0", vname);
Expand Down
4 changes: 2 additions & 2 deletions src/is_sorted.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ static Rboolean is_sorted_double(SEXP x) {
R_xlen_t i = 0;
const R_xlen_t n = xlength(x);
const double * const xr = REAL_RO(x);
while(i < n && xr[i] == NA_REAL) i++;
while(i < n && ISNA(xr[i])) i++;

for (R_xlen_t j = i + 1; j < n; j++) {
if (xr[j] != NA_REAL) {
if (!ISNA(xr[j])) {
if (xr[i] > xr[j])
return FALSE;
i = j;
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_checkNumeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ test_that("sorted works", {
else
expect_true(grepl("sorted", checkNumeric(xu, sorted = TRUE), fixed = TRUE))
}
## see https://github.com/mllg/checkmate/issues/258
expect_true(grepl("sorted", checkNumeric(c(3, NA, 2), sorted = TRUE), fixed = TRUE))
})

test_that("names check works", {
Expand Down
Loading