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

NULL is not considered atomic anymore #246

Merged
merged 9 commits into from
Nov 29, 2023
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.2.0
Version: 2.3.0
Authors@R: c(
person("Michel", "Lang", NULL, "[email protected]",
role = c("cre", "aut"), comment = c(ORCID = "0000-0001-9754-0393")),
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
YEAR: 2023
COPYRIGHT HOLDER: Michel Lang
ORGANIZATION: copyright holder
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Version 2.3.0
* `NULL` is not longer considered to be atomic in future versions of R
(c.f. <https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html>).
To avoid breaking reverse dependencies, checkmate will stick to the old
behavior until further notice.
* Fixed a warning in `checkAtomic()` (#245).

# Version 2.2.0
* Fixed C compiler warnings for windows
* Added `checkPermutation` (#230).
Expand Down
3 changes: 3 additions & 0 deletions R/checkAtomic.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#' @description
#' For the definition of \dQuote{atomic}, see \code{\link[base]{is.atomic}}.
#'
#' Note that `NULL` is recognized as a valid atomic value, as in R versions up to version 4.3.x.
#' For details, see \url{https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html}.
#'
#' @templateVar fn Atomic
#' @template x
#' @inheritParams checkVector
Expand Down
4 changes: 2 additions & 2 deletions R/checkPathForOutput.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#' it is both readable and writable.
#' Default is \code{FALSE}.
#' @param extension [\code{character(1)}]\cr
#' Extension of the file, e.g. dQuote{txt} or \dQuote{tar.gz}.
#' Extension of the file, e.g. \dQuote{txt} or \dQuote{tar.gz}.
#' @template checker
#' @family filesystem
#' @export
Expand Down Expand Up @@ -47,7 +47,7 @@ checkPathForOutput = function(x, overwrite = FALSE, extension = NULL) {
if (!is.null(extension)) {
qassert(extension, "S1")
if (!endsWith(x, paste0(".", extension)))
return(sprintf("File must have extension '.%s'", extension))
return(sprintf("File must have extension '.%s'", extension))
}
return(checkAccess(dn, "w"))
}
Expand Down
2 changes: 1 addition & 1 deletion R/checkScalarNA.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ checkScalarNA = function(x, null.ok = FALSE) {
return(TRUE)
return("Must be a scalar missing value, not 'NULL'")
}
if (length(x) != 1L || !is.na(x))
if (!is.atomic(x) || length(x) != 1L || !is.na(x))
return(paste0("Must be a scalar missing value", if (null.ok) " (or 'NULL')" else ""))
return(TRUE)
}
Expand Down
3 changes: 3 additions & 0 deletions man/checkAtomic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/checkPathForOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/testthat/test_checkAtomic.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ test_that("checkAtomic", {

expect_error(assertAtomic(iris), "atomic")

expect_equal(vlapply(li, is.atomic), vlapply(li, testAtomic))
# handling of is.null for future versions of R, see
# https://stat.ethz.ch/pipermail/r-devel/2023-September/082892.html
expect_equal(vlapply(li, function(x) is.atomic(x) || is.null(x)), vlapply(li, testAtomic))
})
5 changes: 5 additions & 0 deletions tests/testthat/test_checkScalarNA.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ test_that("checkScalarNA", {

expect_error(assertScalarNA(integer(0)), "missing value")
})

test_that("checkScalarNA on data.frame/data.table (#245)", {
df = data.frame(x = 1:2)
expect_false(testScalarNA(df))
})