Skip to content

Commit 2fbed52

Browse files
authored
NULL is not considered atomic anymore (#246)
1 parent c21c718 commit 2fbed52

10 files changed

+27
-6
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Title: Fast and Versatile Argument Checks
44
Description: Tests and assertions to perform frequent argument checks. A
55
substantial part of the package was written in C to minimize any worries
66
about execution time overhead.
7-
Version: 2.2.0
7+
Version: 2.3.0
88
Authors@R: c(
99
person("Michel", "Lang", NULL, "[email protected]",
1010
role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")),

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
YEAR: 2023
22
COPYRIGHT HOLDER: Michel Lang
3+
ORGANIZATION: copyright holder

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Version 2.3.0
2+
* `NULL` is not longer considered to be atomic in future versions of R
3+
(c.f. <https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html>).
4+
To avoid breaking reverse dependencies, checkmate will stick to the old
5+
behavior until further notice.
6+
* Fixed a warning in `checkAtomic()` (#245).
7+
18
# Version 2.2.0
29
* Fixed C compiler warnings for windows
310
* Added `checkPermutation` (#230).

R/checkAtomic.R

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#' @description
44
#' For the definition of \dQuote{atomic}, see \code{\link[base]{is.atomic}}.
55
#'
6+
#' Note that `NULL` is recognized as a valid atomic value, as in R versions up to version 4.3.x.
7+
#' For details, see \url{https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html}.
8+
#'
69
#' @templateVar fn Atomic
710
#' @template x
811
#' @inheritParams checkVector

R/checkPathForOutput.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' it is both readable and writable.
1919
#' Default is \code{FALSE}.
2020
#' @param extension [\code{character(1)}]\cr
21-
#' Extension of the file, e.g. dQuote{txt} or \dQuote{tar.gz}.
21+
#' Extension of the file, e.g. \dQuote{txt} or \dQuote{tar.gz}.
2222
#' @template checker
2323
#' @family filesystem
2424
#' @export
@@ -47,7 +47,7 @@ checkPathForOutput = function(x, overwrite = FALSE, extension = NULL) {
4747
if (!is.null(extension)) {
4848
qassert(extension, "S1")
4949
if (!endsWith(x, paste0(".", extension)))
50-
return(sprintf("File must have extension '.%s'", extension))
50+
return(sprintf("File must have extension '.%s'", extension))
5151
}
5252
return(checkAccess(dn, "w"))
5353
}

R/checkScalarNA.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ checkScalarNA = function(x, null.ok = FALSE) {
1717
return(TRUE)
1818
return("Must be a scalar missing value, not 'NULL'")
1919
}
20-
if (length(x) != 1L || !is.na(x))
20+
if (!is.atomic(x) || length(x) != 1L || !is.na(x))
2121
return(paste0("Must be a scalar missing value", if (null.ok) " (or 'NULL')" else ""))
2222
return(TRUE)
2323
}

man/checkAtomic.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/checkPathForOutput.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_checkAtomic.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ test_that("checkAtomic", {
4747

4848
expect_error(assertAtomic(iris), "atomic")
4949

50-
expect_equal(vlapply(li, is.atomic), vlapply(li, testAtomic))
50+
# handling of is.null for future versions of R, see
51+
# https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html
52+
expect_equal(vlapply(li, function(x) is.atomic(x) || is.null(x)), vlapply(li, testAtomic))
5153
})

tests/testthat/test_checkScalarNA.R

+5
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ test_that("checkScalarNA", {
1010

1111
expect_error(assertScalarNA(integer(0)), "missing value")
1212
})
13+
14+
test_that("checkScalarNA on data.frame/data.table (#245)", {
15+
df = data.frame(x = 1:2)
16+
expect_false(testScalarNA(df))
17+
})

0 commit comments

Comments
 (0)