checkmate/0000755000175100001440000000000012540774710012223 5ustar hornikuserscheckmate/inst/0000755000175100001440000000000012535574765013214 5ustar hornikuserscheckmate/inst/doc/0000755000175100001440000000000012535574765013761 5ustar hornikuserscheckmate/inst/doc/checkmate.R0000644000175100001440000000235412535601543016015 0ustar hornikusers## ------------------------------------------------------------------------ fact <- function(n, method = "stirling") { if (length(n) != 1) stop("Argument 'n' must have length 1") if (!is.numeric(n)) stop("Argument 'n' must be numeric") if (is.na(n)) stop("Argument 'n' may not be NA") if (is.double(n)) { if (is.nan(n)) stop("Argument 'n' may not be NaN") if (is.infinite(n)) stop("Argument 'n' must be finite") if (abs(n - round(n, 0)) > sqrt(.Machine$double.eps)) stop("Argument 'n' must be an integerish value") n <- as.integer(n) } if (n < 0) stop("Argument 'n' must be >= 0") if (length(method) != 1) stop("Argument 'method' must have length 1") if (!is.character(method) || !method %in% c("stirling", "factorial")) stop("Argument 'method' must be either 'stirling' or 'factorial'") if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } ## ------------------------------------------------------------------------ fact <- function(n, method = "stirling") { library(checkmate) assertCount(n) assertChoice(method, c("stirling", "factorial")) if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } checkmate/inst/doc/checkmate.Rmd0000644000175100001440000001536012535601543016337 0ustar hornikusers--- title: "Checkmate" author: "Michel Lang" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Vignette Title} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- Ever used an R function that produced a not-very-helpful error message, just to discover after minutes of debugging that you simply passed a wrong argument? Blaming the laziness of the package author for not doing such standard checks (in a dynamically typed language such as R) is at least partially unfair, as R makes theses types of checks cumbersome and annoying. Well, that's how it was in the past. Enter checkmate. Virtually **every standard type of user error** when passing arguments into function can be caught with a simple, readable line which produces an **informative error message** in case. A substantial part of the package was written in C to **minimize any worries about execution time overhead**. ## Intro As a motivational example, consider you have a function to calculate the faculty of a natural number and the user may choose between using either the stirling approximation or R's `factorial` function (which internally uses the gamma function). Thus, you have two arguments, `n` and `method`. Argument `n` must obviously be a positive natural number and `method` must be either `"stirling"` or `"factorial"`. Here is a version of all the hoops you need to jump through to ensure that these simple requirements are met: ```{r} fact <- function(n, method = "stirling") { if (length(n) != 1) stop("Argument 'n' must have length 1") if (!is.numeric(n)) stop("Argument 'n' must be numeric") if (is.na(n)) stop("Argument 'n' may not be NA") if (is.double(n)) { if (is.nan(n)) stop("Argument 'n' may not be NaN") if (is.infinite(n)) stop("Argument 'n' must be finite") if (abs(n - round(n, 0)) > sqrt(.Machine$double.eps)) stop("Argument 'n' must be an integerish value") n <- as.integer(n) } if (n < 0) stop("Argument 'n' must be >= 0") if (length(method) != 1) stop("Argument 'method' must have length 1") if (!is.character(method) || !method %in% c("stirling", "factorial")) stop("Argument 'method' must be either 'stirling' or 'factorial'") if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } ``` And for comparison, here is the same function using checkmate: ```{r} fact <- function(n, method = "stirling") { library(checkmate) assertCount(n) assertChoice(method, c("stirling", "factorial")) if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } ``` ## Function overview ### Scalars * [checkFlag](http://www.rdocumentation.org/packages/checkmate/functions/checkFlag) * [checkCount](http://www.rdocumentation.org/packages/checkmate/functions/checkCount) * [checkInt](http://www.rdocumentation.org/packages/checkmate/functions/checkInt) * [checkNumber](http://www.rdocumentation.org/packages/checkmate/functions/checkNumber) * [checkString](http://www.rdocumentation.org/packages/checkmate/functions/checkString) * [checkScalar](http://www.rdocumentation.org/packages/checkmate/functions/checkScalar) * [checkScalarNA](http://www.rdocumentation.org/packages/checkmate/functions/checkScalarNA) * [checkPercentage](http://www.rdocumentation.org/packages/checkmate/functions/checkPercentage) ### Vectors * [checkLogical](http://www.rdocumentation.org/packages/checkmate/functions/checkLogical) * [checkNumeric](http://www.rdocumentation.org/packages/checkmate/functions/checkNumeric) * [checkInteger](http://www.rdocumentation.org/packages/checkmate/functions/checkInteger) * [checkIntegerish](http://www.rdocumentation.org/packages/checkmate/functions/checkIntegerish) * [checkComplex](http://www.rdocumentation.org/packages/checkmate/functions/checkComplex) * [checkCharacter](http://www.rdocumentation.org/packages/checkmate/functions/checkCharacter) * [checkFactor](http://www.rdocumentation.org/packages/checkmate/functions/checkFactor) * [checkList](http://www.rdocumentation.org/packages/checkmate/functions/checkList) * [checkVector](http://www.rdocumentation.org/packages/checkmate/functions/checkVector) * [checkAtomic](http://www.rdocumentation.org/packages/checkmate/functions/checkAtomic) * [checkAtomicVector](http://www.rdocumentation.org/packages/checkmate/functions/checkAtomicVector) ### Attributes * [checkClass](http://www.rdocumentation.org/packages/checkmate/functions/checkClass) * [checkNames](http://www.rdocumentation.org/packages/checkmate/functions/checkNames) * [checkNamed](http://www.rdocumentation.org/packages/checkmate/functions/checkNamed) ### Choices and Subsets * [checkChoice](http://www.rdocumentation.org/packages/checkmate/functions/checkChoice) * [checkSubset](http://www.rdocumentation.org/packages/checkmate/functions/checkSubset) * [checkSetEqual](http://www.rdocumentation.org/packages/checkmate/functions/checkSetEqual) ### Matrices, Arrays and Data Frame * [checkMatrix](http://www.rdocumentation.org/packages/checkmate/functions/checkMatrix) * [checkArray](http://www.rdocumentation.org/packages/checkmate/functions/checkArray) * [checkDataFrame](http://www.rdocumentation.org/packages/checkmate/functions/checkDataFrame) ### Safe Coercion to integer * [asCount](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) * [asInt](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) * [asInteger](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) ### Other builtin * [checkNull](http://www.rdocumentation.org/packages/checkmate/functions/checkNull) * [checkEnvironment](http://www.rdocumentation.org/packages/checkmate/functions/checkEnvironment) * [checkFunction](http://www.rdocumentation.org/packages/checkmate/functions/checkFunction) ### File IO: * [checkFile](http://www.rdocumentation.org/packages/checkmate/functions/checkFile) * [checkDirectory](http://www.rdocumentation.org/packages/checkmate/functions/checkDirectory) * [checkPathForOutput](http://www.rdocumentation.org/packages/checkmate/functions/checkPathForOutput) ## In case you miss flexibility You can use [assert](http://www.rdocumentation.org/packages/checkmate/functions/assert) to perform multiple checks at once and throw an assertion if all checks fail. ## Argument Checks for the Lazy The follwoing functions allow a special syntax to define argument checks using a special pattern. E.g., `qassert(x, "I+")` asserts that `x` is an integer vector with at least one element and no missing values. This provide a completely alternative mini-language (or style) how to perform argument checks. You choose what you like best. * [qassert](http://www.rdocumentation.org/packages/checkmate/functions/qassert) * [qassertr](http://www.rdocumentation.org/packages/checkmate/functions/qassert) checkmate/inst/doc/checkmate.html0000644000175100001440000004533412535601543016565 0ustar hornikusers Checkmate

Ever used an R function that produced a not-very-helpful error message, just to discover after minutes of debugging that you simply passed a wrong argument?

Blaming the laziness of the package author for not doing such standard checks (in a dynamically typed language such as R) is at least partially unfair, as R makes theses types of checks cumbersome and annoying. Well, that’s how it was in the past.

Enter checkmate.

Virtually every standard type of user error when passing arguments into function can be caught with a simple, readable line which produces an informative error message in case. A substantial part of the package was written in C to minimize any worries about execution time overhead.

Intro

As a motivational example, consider you have a function to calculate the faculty of a natural number and the user may choose between using either the stirling approximation or R’s factorial function (which internally uses the gamma function). Thus, you have two arguments, n and method. Argument n must obviously be a positive natural number and method must be either "stirling" or "factorial". Here is a version of all the hoops you need to jump through to ensure that these simple requirements are met:

fact <- function(n, method = "stirling") {
  if (length(n) != 1)
    stop("Argument 'n' must have length 1")
  if (!is.numeric(n))
    stop("Argument 'n' must be numeric")
  if (is.na(n))
    stop("Argument 'n' may not be NA")
  if (is.double(n)) {
    if (is.nan(n))
      stop("Argument 'n' may not be NaN")
    if (is.infinite(n))
      stop("Argument 'n' must be finite")
    if (abs(n - round(n, 0)) > sqrt(.Machine$double.eps))
      stop("Argument 'n' must be an integerish value")
    n <- as.integer(n)
  }
  if (n < 0)
    stop("Argument 'n' must be >= 0")
  if (length(method) != 1)
    stop("Argument 'method' must have length 1")
  if (!is.character(method) || !method %in% c("stirling", "factorial"))
    stop("Argument 'method' must be either 'stirling' or 'factorial'")

  if (method == "factorial")
    factorial(n)
  else
    sqrt(2 * pi * n) * (n / exp(1))^n
}

And for comparison, here is the same function using checkmate:

fact <- function(n, method = "stirling") {
  library(checkmate)
  assertCount(n)
  assertChoice(method, c("stirling", "factorial"))

  if (method == "factorial")
    factorial(n)
  else
    sqrt(2 * pi * n) * (n / exp(1))^n
}

Function overview

Scalars

Vectors

Attributes

Choices and Subsets

Matrices, Arrays and Data Frame

Safe Coercion to integer

Other builtin

File IO:

In case you miss flexibility

You can use assert to perform multiple checks at once and throw an assertion if all checks fail.

Argument Checks for the Lazy

The follwoing functions allow a special syntax to define argument checks using a special pattern. E.g., qassert(x, "I+") asserts that x is an integer vector with at least one element and no missing values. This provide a completely alternative mini-language (or style) how to perform argument checks. You choose what you like best.

checkmate/tests/0000755000175100001440000000000012514153643013362 5ustar hornikuserscheckmate/tests/test-all.r0000755000175100001440000000005212514153643015272 0ustar hornikuserslibrary(testthat) test_check("checkmate") checkmate/tests/testthat/0000755000175100001440000000000012536305345015224 5ustar hornikuserscheckmate/tests/testthat/test_checkPercentage.r0000644000175100001440000000123512514153643021520 0ustar hornikuserscontext("checkPercentage") test_that("checkPercentage", { myobj = 1 expect_succ(Percentage, myobj) myobj = 2 expect_fail(Percentage, myobj) expect_false(testPercentage(integer(0))) expect_false(testPercentage(NULL)) expect_false(testPercentage(-1)) expect_true(testPercentage(1L)) expect_true(testPercentage(1.)) expect_false(testPercentage(NA)) expect_false(testPercentage(NaN)) expect_true(testPercentage(NaN, na.ok = TRUE)) expect_true(testPercentage(NA_real_, na.ok = TRUE)) expect_false(testPercentage(1:2)) expect_false(testPercentage("")) expect_false(testPercentage(TRUE)) expect_error(assertPercentage(2+3i), "number") }) checkmate/tests/testthat/test_asType.r0000644000175100001440000000432212514153643017712 0ustar hornikuserscontext("asType") test_that("asInteger", { xi = 1:5 xd = as.double(1:5) xc = as.complex(1:5) expect_equal(asInteger(xi), xi) expect_equal(asInteger(xd), xi) expect_equal(asInteger(xc), xi) expect_equal(asInteger(NA), NA_integer_) expect_equal(names(asInteger(xi)), names(xi)) expect_equal(names(asInteger(xd)), names(xd)) expect_equal(names(asInteger(xc)), names(xc)) names(xi) = names(xd) = names(xc) = letters[1:5] expect_equal(names(asInteger(xi)), names(xi)) expect_equal(names(asInteger(xd)), names(xd)) expect_equal(names(asInteger(xc)), names(xc)) expect_error(asInteger("a")) expect_error(asInteger(3+1i)) expect_error(asInteger(iris)) expect_error(asInteger(NA, any.missing = FALSE), "missing") }) test_that("asInt", { xi = 1L xd = 1. xc = as.complex(1) expect_equal(names(asInt(xi)), names(xi)) expect_equal(names(asInt(xd)), names(xd)) expect_equal(names(asInt(xc)), names(xc)) names(xi) = names(xd) = names(xc) = "a" expect_equal(names(asInt(xi)), names(xi)) expect_equal(names(asInt(xd)), names(xd)) expect_equal(names(asInt(xc)), names(xc)) expect_error(asInt(1:2), "integerish") expect_equal(asInt(xi), xi) expect_equal(asInt(xd), xi) expect_equal(asInt(xc), xi) expect_error(asInt(NA), "NA") expect_equal(asInt(NA, na.ok = TRUE), NA_integer_) expect_error(asInt("a")) expect_error(asInt(3+1i)) expect_error(asInt(iris)) expect_error(asInt(xi, lower = 2), ">=") }) test_that("asCount", { xi = 1L xd = 1. xc = as.complex(1) expect_equal(names(asCount(xi)), names(xi)) expect_equal(names(asCount(xd)), names(xd)) expect_equal(names(asCount(xc)), names(xc)) names(xi) = names(xd) = names(xc) = "a" expect_equal(names(asCount(xi)), names(xi)) expect_equal(names(asCount(xd)), names(xd)) expect_equal(names(asCount(xc)), names(xc)) expect_error(asCount(1:2), "count") expect_equal(asCount(xi), xi) expect_equal(asCount(xd), xi) expect_equal(asCount(xc), xi) expect_error(asCount(NA), "NA") expect_equal(asCount(NA, na.ok = TRUE), NA_integer_) expect_error(asCount("a")) expect_error(asCount(3+1i)) expect_error(asCount(iris)) expect_error(asCount(0, positive = TRUE)) expect_equal(asCount(1, positive = FALSE), 1L) }) checkmate/tests/testthat/test_checkDataFrame.r0000644000175100001440000000504012524117441021262 0ustar hornikuserscontext("checkDataFrame") test_that("checkDataFrame", { myobj = iris expect_succ(DataFrame, myobj) myobj = TRUE expect_fail(DataFrame, myobj) expect_true(testDataFrame(data.frame())) expect_false(testDataFrame(NULL)) expect_true(testDataFrame(data.frame(1))) expect_true(testDataFrame(iris)) expect_false(testDataFrame(list(1))) x = iris expect_true(testDataFrame(x, types = c("numeric", "factor"))) expect_false(testDataFrame(x, types = c("integer", "factor"))) expect_false(testDataFrame(x, types = c("numeric", "character"))) expect_true(testDataFrame(data.frame(), types = "NULL")) expect_true(testDataFrame(data.frame(), types = "numeric")) expect_error(assertDataFrame(1), "data.frame") expect_error(assertDataFrame(x, types = "numeric"), "types: numeric") # check nrow and ncol constraints expect_true(testDataFrame(x, nrows = 150L, ncols = 5L)) expect_false(testDataFrame(x, nrows = 150L, ncols = 7L)) expect_true(testDataFrame(x, min.rows = 2L, min.cols = 4L)) expect_false(testDataFrame(x, min.rows = 151L, min.cols = 4L)) expect_false(testDataFrame(x, min.rows = 1L, min.cols = 6L)) }) test_that("checkDataFrame name checking works", { df = data.frame(x = 1:2, y = 1:2) names(df) = c("x", "x") expect_true(assertDataFrame(df)) expect_error(assertDataFrame(df, col.names = "unnamed"), "unnamed") names(df) = c("x", "") expect_error(assertDataFrame(df, col.names = "named"), "named") names(df) = c("x", "x") expect_true(assertDataFrame(df, col.names = "named")) expect_error(assertDataFrame(df, col.names = "unique"), "uniquely") expect_error(assertDataFrame(df, col.names = "strict"), "uniquely") names(df) = c("x", "1") expect_true(assertDataFrame(df, col.names = "named")) expect_true(assertDataFrame(df, col.names = "unique")) expect_error(assertDataFrame(df, col.names = "strict"), "naming rules") rownames(df) = NULL expect_error(assertDataFrame(df, row.names = "unnamed"), "unnamed") expect_true(assertDataFrame(df, row.names = "named")) expect_error(assertDataFrame(df, row.names = "strict"), "naming rules") }) test_that("dimension checks work for empty frames", { x = iris[, -c(1:5)] expect_true(testDataFrame(x, min.rows = 5)) expect_true(testDataFrame(x, nrows = 150)) expect_false(testDataFrame(x, min.rows = 151)) expect_false(testDataFrame(x, nrows = 1)) x = iris[-c(1:150), ] expect_true(testDataFrame(x, min.cols = 1)) expect_true(testDataFrame(x, ncols = 5)) expect_false(testDataFrame(x, min.cols = 6)) expect_false(testDataFrame(x, ncols = 1)) }) checkmate/tests/testthat/test_checkFlag.r0000644000175100001440000000072012514153643020312 0ustar hornikuserscontext("checkFlag") test_that("checkFlag", { myobj = TRUE expect_succ(Flag, myobj) myobj = NA expect_fail(Flag, myobj) expect_false(testFlag(logical(0))) expect_false(testFlag(NULL)) expect_true(testFlag(TRUE)) expect_true(testFlag(FALSE)) expect_false(testFlag(NA)) expect_true(testFlag(NA, na.ok = TRUE)) expect_true(testFlag(NA_character_, na.ok = TRUE)) expect_false(testFlag(iris)) expect_error(assertFlag(1), "logical flag") }) checkmate/tests/testthat/test_checkClass.r0000644000175100001440000000175712514153643020521 0ustar hornikuserscontext("checkClass") test_that("checkClass", { myobj = 1 expect_succ(Class, myobj, "numeric") expect_fail(Class, myobj, "integer") expect_true(testClass(NULL, "NULL")) expect_true(testClass(1, "numeric")) expect_true(testClass(1L, "integer")) expect_false(testClass(1, "integer")) foo = 1 class(foo) = c("a", "b") expect_true(testClass(foo, "a")) expect_true(testClass(foo, "b")) expect_false(testClass(foo, "c")) expect_true(testClass(foo, "a", ordered=TRUE)) expect_false(testClass(foo, "b", ordered=TRUE)) expect_true(testClass(foo, c("a", "b"), ordered=TRUE)) expect_false(testClass(foo, c("b", "a"), ordered=TRUE)) foo = 1 class(foo) = c("a", "b") expect_error(assertClass(foo, "c"), "Must have class 'c', but has classes 'a','b'") expect_error(assertClass(foo, "b", ordered=TRUE), "Must have class 'b' in position 1, but has classes 'a','b'") foo = 1 class(foo) = "a" expect_error(assertClass(foo, "c"), "Must have class 'c', but has class 'a'") }) checkmate/tests/testthat/test_checkCount.r0000644000175100001440000000121212514153643020526 0ustar hornikuserscontext("checkCount") test_that("checkCount", { myobj = 1 expect_succ(Count, myobj) myobj = -1 expect_fail(Count, myobj) expect_false(testCount(integer(0))) expect_false(testCount(NULL)) expect_true(testCount(0L)) expect_false(testCount(0L, positive = TRUE)) expect_true(testCount(1L, positive = TRUE)) expect_true(testCount(1)) expect_true(testCount(0)) expect_false(testCount(-1)) expect_false(testCount(0.5)) expect_false(testCount(NA_integer_)) expect_true(testCount(NA, na.ok = TRUE)) expect_true(testCount(NA_integer_, na.ok = TRUE)) expect_false(testCount(1:2)) expect_error(assertCount(-1), ">= 0") }) checkmate/tests/testthat/test_wfwl.r0000644000175100001440000000046412514153643017427 0ustar hornikuserscontext("which.first") test_that("which.first", { x = c(NA, FALSE, TRUE, FALSE, TRUE, FALSE, NA) expect_equal(wf(x), 3) expect_equal(wl(x), 5) expect_equal(wf(logical(0)), integer(0)) expect_equal(wl(logical(0)), integer(0)) expect_error(wf(42), "logical") expect_error(wl(42), "logical") }) checkmate/tests/testthat/test_checkLogical.r0000644000175100001440000000111512514153643021012 0ustar hornikuserscontext("checkLogical") test_that("checkLogical", { myobj = TRUE expect_succ(Logical, myobj) myobj = 1 expect_fail(Logical, myobj) expect_true(testLogical(logical(0))) expect_false(testLogical(NULL)) expect_true(testLogical(TRUE)) expect_true(testLogical(NA)) expect_true(testLogical(NA_real_)) expect_true(testLogical(FALSE)) expect_false(testLogical(NA, any.missing=FALSE)) expect_false(testLogical(NA, all.missing=FALSE)) expect_false(testLogical(iris)) expect_true(testLogical(c(TRUE, FALSE), min.len = 2)) expect_error(assertLogical(1), "logical") }) checkmate/tests/testthat/test_wf.r0000644000175100001440000000077312514153643017067 0ustar hornikuserscontext("wf / wl") test_that("wf / wl", { wf = checkmate:::wf wl = checkmate:::wl x = c(FALSE, TRUE, FALSE, TRUE) expect_equal(wf(x), 2L) expect_equal(wl(x), 4L) x = c(NA, TRUE, NA, TRUE, NA) expect_equal(wf(x), 2L) expect_equal(wl(x), 4L) x = logical(0L) expect_equal(wf(x), integer(0L)) expect_equal(wl(x), integer(0L)) expect_equal(wf(x), integer(0L)) expect_equal(wl(x), integer(0L)) x = c(NA, NA) expect_equal(wf(x), integer(0L)) expect_equal(wl(x), integer(0L)) }) checkmate/tests/testthat/test_qtestr.r0000644000175100001440000000203412514153643017765 0ustar hornikuserscontext("qtestr") expect_succ = function(x, rules) { expect_true(qtestr(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) expect_true(qassertr(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) } expect_fail = function(x, rules) { expect_false(qtestr(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) expect_true(inherits(try(qassertr(x, rules), silent=TRUE), "try-error"), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) } test_that("qtestr", { x = list(a=1:10, b=rnorm(10)) expect_succ(x, "n+") expect_succ(x, "n10") expect_succ(x, "n>=1") expect_fail(x, "i+") expect_fail(x, "l") x = list(a = NULL, b = 10) expect_succ(x, "*") expect_fail(x, "0") expect_fail(x, "n") x = list(a = NULL, b = NULL) expect_succ(x, "0") expect_fail(x, "0+") x = list() expect_succ(x, "n+") expect_succ(x, "0+") }) checkmate/tests/testthat/test_checkSetEqual.r0000644000175100001440000000243112514153643021165 0ustar hornikuserscontext("checkSetEqual") test_that("checkSetEqual", { myobj = letters[1:3] expect_succ(SetEqual, myobj, letters[1:3]) myobj = letters[1:2] expect_fail(String, myobj, letters[1:3]) expect_true(testSetEqual(character(0), character(0))) expect_true(testSetEqual(character(0), character(0), ordered = TRUE)) expect_false(testSetEqual(character(0), letters)) expect_false(testSetEqual(letters, character(0))) expect_false(testSetEqual(NULL, letters)) expect_false(testSetEqual(NULL, letters, ordered = TRUE)) expect_true(testSetEqual(1L, 1L)) expect_true(testSetEqual(3:4, 3:4)) expect_true(testSetEqual(NA_integer_, NA_integer_)) expect_true(testSetEqual(NA_integer_, NA)) expect_true(testSetEqual(1:2, 1:2, ordered = TRUE)) expect_false(testSetEqual(1:2, 2:1, ordered = TRUE)) expect_true(testSetEqual(NA, NA, ordered = TRUE)) expect_false(testSetEqual(NA_integer_, 1L, ordered = TRUE)) expect_false(testSetEqual(1L, NA_integer_, ordered = TRUE)) expect_true(testSetEqual(NA_integer_, NA, ordered = TRUE)) expect_false(testSetEqual(c(NA_integer_, 2L), 1:2, ordered = TRUE)) expect_true(testSetEqual(c(NA_integer_, 2L), c(NA_real_, 2), ordered = TRUE)) expect_error(assertSetEqual(1, 1:2), "equal to") expect_error(assertSetEqual(1L, list()), "atomic") }) checkmate/tests/testthat/test_checkNamed.r0000644000175100001440000000334412514153643020472 0ustar hornikuserscontext("checkNamed") test_that("checkNamed", { myobj = setNames(1:3, letters[1:3]) expect_succ(Named, myobj) myobj = 1:3 expect_fail(Named, myobj) expect_true(testNamed(integer(0))) expect_true(testNamed(NULL)) expect_true(testNamed(setNames(integer(0), character(0)))) x = setNames(1:2, c("a", ".a")) expect_true(testNamed(x)) expect_true(testNamed(x, "unique")) expect_true(testNamed(x, "strict")) expect_false(testNamed(1)) expect_false(testNamed(setNames(x, NA_character_))) expect_false(testNamed(setNames(x, NA_integer_))) expect_false(testNamed(setNames(x, ""))) x = setNames(1:2, c("a", "a")) expect_true(testNamed(x)) expect_false(testNamed(x, "unique")) x = setNames(1:2, c("a", "1")) expect_true(testNamed(x)) expect_false(testNamed(x, "strict")) x = setNames(1:2, c("a", "..1")) expect_true(testNamed(x)) expect_false(testNamed(x, "strict")) x = setNames(1, "") expect_error(assertNamed(x), "named") x = setNames(1:2, c("a", "a")) expect_error(assertNamed(x, "unique"), "uniquely") expect_true(testNamed(setNames(1, "x"), type = "strict")) expect_true(testNamed(setNames(1, "..x"), type = "strict")) expect_true(testNamed(setNames(1, "x_1"), type = "strict")) expect_true(testNamed(setNames(1, "x."), type = "strict")) expect_false(testNamed(setNames(1, "1"), type = "strict")) expect_false(testNamed(setNames(1, ".1"), type = "strict")) expect_false(testNamed(setNames(1, "..1"), type = "strict")) expect_false(testNamed(setNames(1, "x "), type = "strict")) expect_false(testNamed(setNames(1, "ä"), type = "strict")) expect_error(assertNamed(x, "unique"), "uniquely") x = setNames(1:2, c("a", "1")) expect_error(assertNamed(x, "strict"), "naming rules") }) checkmate/tests/testthat/test_checkAtomic.r0000644000175100001440000000255012514153643020660 0ustar hornikuserscontext("checkAtomic") li = list( list = list(1, 2), factor = factor("a"), integer = 1:2, NULL = NULL, data.frame = iris ) test_that("checkAtomic", { myobj = 1:2 expect_succ(Atomic, myobj) myobj = iris expect_fail(Atomic, myobj) expect_true(testAtomic(integer(0))) expect_true(testAtomic(NULL)) expect_true(testAtomic(1)) expect_true(testAtomic(integer(0))) expect_true(testAtomic(factor(1))) expect_true(testAtomic(NA, any.missing = TRUE)) expect_false(testAtomic(NA, any.missing = FALSE)) expect_false(testAtomic(NA, all.missing = FALSE)) expect_true(testAtomic(1, len=1)) expect_false(testAtomic(1, len=0)) expect_true(testAtomic(1, min.len=0)) expect_false(testAtomic(1, min.len=2)) expect_true(testAtomic(1, max.len=1)) expect_false(testAtomic(1, max.len=0)) expect_true(testAtomic(1, unique=TRUE)) expect_false(testAtomic(1, min.len=2)) expect_true(testAtomic(1, max.len=1)) expect_false(testAtomic(1, max.len=0)) expect_true(testAtomic(1, unique=TRUE)) expect_true(testAtomic(c(1,1), unique=FALSE)) expect_false(testAtomic(c(1,1), unique=TRUE)) expect_true(testAtomic(1, names="unnamed")) expect_true(testAtomic(setNames(1, "x"), names="named")) expect_false(testAtomic(1, names="unique")) expect_error(assertAtomic(iris), "atomic") expect_equal(sapply(li, is.atomic), sapply(li, testAtomic)) }) checkmate/tests/testthat/test_checkAtomicVector.r0000644000175100001440000000341412524324060022035 0ustar hornikuserscontext("checkAtomicVector") li = list( list = list(1, 2), factor = factor("a"), integer = 1:2, NULL = NULL, data.frame = iris ) test_that("checkAtomicVector", { myobj = 1:2 expect_succ(AtomicVector, myobj) myobj = NULL expect_fail(AtomicVector, myobj) expect_true(testAtomicVector(integer(0))) expect_false(testAtomicVector(NULL)) expect_true(testAtomicVector(1)) expect_true(testAtomicVector(integer(0))) expect_true(testAtomicVector(factor(1))) expect_true(testAtomicVector(NA, any.missing = TRUE)) expect_false(testAtomicVector(NA, any.missing = FALSE)) expect_false(testAtomicVector(NA, all.missing = FALSE)) expect_true(testAtomicVector(1, len=1)) expect_false(testAtomicVector(1, len=0)) expect_true(testAtomicVector(1, min.len=0)) expect_false(testAtomicVector(1, min.len=2)) expect_true(testAtomicVector(1, max.len=1)) expect_false(testAtomicVector(1, max.len=0)) expect_true(testAtomicVector(1, unique=TRUE)) expect_false(testAtomicVector(1, min.len=2)) expect_true(testAtomicVector(1, max.len=1)) expect_false(testAtomicVector(1, max.len=0)) expect_true(testAtomicVector(1, unique=TRUE)) expect_true(testAtomicVector(c(1,1), unique=FALSE)) expect_false(testAtomicVector(c(1,1), unique=TRUE)) expect_true(testAtomicVector(1, names="unnamed")) expect_true(testAtomicVector(setNames(1, "x"), names="named")) expect_false(testAtomicVector(1, names="unique")) expect_error(assertAtomicVector(iris), "atomic") expected = setNames(c(FALSE, TRUE, TRUE, FALSE, FALSE), c("list", "factor", "integer", "NULL", "data.frame")) expect_equal(expected, sapply(li, testAtomicVector)) }) test_that("type guessing works (#48)", { x = structure(list(1:4, letters[1:3]), dim = c(2, 1)) expect_match(checkAtomic(x), "list") }) checkmate/tests/testthat/test_checkComplex.r0000644000175100001440000000117312514153643021053 0ustar hornikuserscontext("checkComplex") test_that("checkComplex", { myobj = 1+1i expect_succ(Complex, myobj) myobj = 1 expect_fail(Complex, myobj) expect_true(testComplex(complex(0))) expect_false(testComplex(NULL)) expect_false(testComplex(TRUE)) expect_true(testComplex(NA)) expect_false(testComplex(NA, any.missing = FALSE)) expect_false(testComplex(NA, all.missing = FALSE)) expect_true(testComplex(NA_complex_)) expect_true(testComplex(1+1i)) expect_true(testComplex(as.complex(Inf))) expect_true(testComplex(c(1+1i, 2+1i), any.missing=FALSE, min.len=1L, max.len=3L)) expect_error(assertComplex(1), "complex") }) checkmate/tests/testthat/test_guessType.r0000644000175100001440000000157312514153643020442 0ustar hornikuserscontext("guessType") test_that("guessType", { xb = logical(10) xi = integer(10) xd = double(10) xc = complex(10) xs = letters[1:10] xl = as.list(1:10) xm = matrix(1:9, 3) xa = array(1:3) xf = data.frame(a=1:5, b=1:5) expect_true(grepl("NULL'$", checkLogical(NULL))) expect_true(grepl("logical'$", checkInteger(xb))) expect_true(grepl("integer'$", checkLogical(xi))) expect_true(grepl("double'$", checkLogical(xd))) expect_true(grepl("complex'$", checkLogical(xc))) expect_true(grepl("character'$", checkLogical(xs))) expect_true(grepl("factor'$", checkLogical(factor(xs)))) expect_true(grepl("list'$", checkLogical(xl))) expect_true(grepl("matrix'$", checkLogical(xm))) expect_true(grepl("array'$", checkLogical(xa))) expect_true(grepl("frame'$", checkLogical(xf))) x = 1; class(x) = "myclass"; expect_true(grepl("myclass'$", checkLogical(x))) }) checkmate/tests/testthat/test_checkScalarNA.r0000644000175100001440000000042112514153643021063 0ustar hornikuserscontext("checkScalarNA") test_that("checkScalarNA", { expect_true(testScalarNA(NA)) expect_true(testScalarNA(NA_real_)) expect_false(testScalarNA(1)) expect_false(testScalarNA(rep(NA_character_, 2))) expect_error(assertScalarNA(integer(0)), "missing value") }) checkmate/tests/testthat/test_checkFactor.r0000644000175100001440000000327512514153643020667 0ustar hornikuserscontext("checkFactor") test_that("checkFactor", { myobj = factor(letters[1:2]) expect_succ(Factor, myobj) myobj = letters[1:2] expect_fail(Factor, myobj) x = factor(c("a", "b"), levels = c("a", "b")) expect_true(testFactor(x)) expect_false(testFactor(integer(1))) expect_false(testFactor("a")) expect_true(testFactor(factor())) # expect_false(testFactor(integer(0))) expect_false(testFactor(NULL)) expect_true(testFactor(x, levels = rev(levels(x)))) expect_true(testFactor(x, empty.levels.ok = FALSE)) expect_true(testFactor(x, ordered = FALSE)) expect_false(testFactor(x, levels = c("a"))) expect_false(testFactor(x, levels = c("a", "b", "c"))) x = factor(c("a", "b"), levels = c("a", "b", "c"), ordered = TRUE) expect_true(testFactor(x, empty.levels.ok = TRUE)) expect_false(testFactor(x, empty.levels.ok = FALSE)) expect_true(testFactor(x, ordered = TRUE)) expect_false(testFactor(x, ordered = FALSE)) x = factor(c("a", "b"), levels = c("a", "b", "c")) expect_error(assertFactor(1), "factor") expect_error(assertFactor(x, levels = c("a")), "levels") expect_error(assertFactor(x, empty.levels.ok = FALSE), "empty") expect_error(assertFactor(x, ordered = TRUE), "ordered") x = as.ordered(x) expect_error(assertFactor(x, ordered = FALSE), "unordered") x = factor(c("a", "b")) expect_true(testFactor(x, n.levels = 2)) expect_true(testFactor(x, min.levels = 2)) expect_true(testFactor(x, max.levels = 2)) expect_false(testFactor(x, n.levels = 1)) expect_false(testFactor(x, min.levels = 3)) expect_false(testFactor(x, max.levels = 1)) expect_error(testFactor(x, n.levels = NA)) expect_error(assertFactor(x, n.levels = 1), "exactly 1 level") }) checkmate/tests/testthat/test_checkList.r0000644000175100001440000000177112514153643020363 0ustar hornikuserscontext("checkList") test_that("checkList", { myobj = list(1, 2, 3) expect_succ(List, myobj) myobj = TRUE expect_fail(List, myobj) expect_true(testList(list())) expect_false(testList(NULL)) expect_true(testList(list(1))) expect_false(testList(iris)) x = as.list(iris) expect_true(testList(x, types = c("numeric", "factor"))) expect_false(testList(x, types = c("integer", "factor"))) expect_false(testList(x, types = c("numeric", "character"))) expect_true(testList(x, types = c("vector", "factor"))) expect_true(testList(list(NULL), types = "NULL")) expect_true(testList(list(), types = "numeric")) expect_false(testList(list(TRUE), types = "numeric")) expect_error(assertList(x, types = "numeric"), "types: numeric") expect_error(assertList(x, len = 33), "Must have length 33") expect_true(testList(list(), names = "named")) x = 1:3 class(x) = "foo" x = list(x, 1:3) expect_true(testList(x, types = c("foo", "integerish"))) expect_error(assertList(1), "list") }) checkmate/tests/testthat/test_checkVector.r0000644000175100001440000000457712514153643020721 0ustar hornikuserscontext("checkVector") li = list( list = list(1, 2), factor = factor("a"), integer = 1:2, NULL = NULL, data.frame = iris ) test_that("checkVector", { myobj = 1:3 expect_succ(Vector, myobj) myobj = NULL expect_fail(Vector, myobj) expect_true(testVector(integer(0))) expect_false(testVector(NULL)) expect_true(testVector(1)) expect_true(testVector(integer(0))) expect_true(testVector(factor(1), strict = FALSE)) expect_false(testVector(factor(1), strict = TRUE)) expect_true(testVector(NA, any.missing = TRUE)) expect_false(testVector(NA, any.missing = FALSE)) expect_false(testVector(NA, all.missing = FALSE)) expect_true(testVector(1, len=1)) expect_false(testVector(1, len=0)) expect_true(testVector(1, min.len=0)) expect_false(testVector(1, min.len=2)) expect_true(testVector(1, max.len=1)) expect_false(testVector(1, max.len=0)) expect_true(testVector(1, unique=TRUE)) expect_false(testVector(1, min.len=2)) expect_true(testVector(1, max.len=1)) expect_false(testVector(1, max.len=0)) expect_true(testVector(1, unique=TRUE)) expect_true(testVector(c(1,1), unique=FALSE)) expect_false(testVector(c(1,1), unique=TRUE)) expect_true(testVector(1, names="unnamed")) expect_true(testVector(setNames(1, "x"), names="named")) expect_false(testVector(1, names="unique")) expect_equal(sapply(li, is.vector), sapply(li, testVector, strict = TRUE)) expected = setNames(c(TRUE, TRUE, TRUE, FALSE, TRUE), c("list", "factor", "integer", "NULL", "data.frame")) expect_equal(expected, sapply(li, testVector, strict = FALSE)) expect_error(assertVector(iris, strict = TRUE), "vector") }) test_that("arguments any.missing and all.missing are checked", { x = 1 expect_error(checkVector(x, any.missing = 1), "flag") expect_error(checkVector(x, any.missing = NA), "missing") expect_error(checkVector(x, all.missing = 1), "flag") expect_error(checkVector(x, all.missing = NA), "missing") }) test_that("length is correctly reported", { x = 1:42 expect_true(grepl(42, checkVector(x, len = 1), fixed = TRUE)) expect_true(grepl(42, checkVector(x, min.len = 43), fixed = TRUE)) expect_true(grepl(42, checkVector(x, max.len = 1), fixed = TRUE)) expect_true(grepl(43, checkVector(x, len = 43), fixed = TRUE)) expect_true(grepl(43, checkVector(x, min.len = 43), fixed = TRUE)) expect_true(grepl(41, checkVector(x, max.len = 41), fixed = TRUE)) }) checkmate/tests/testthat/test_checkArray.r0000644000175100001440000000274412524330355020525 0ustar hornikuserscontext("checkArray") test_that("checkArray", { myobj = array(1:2) expect_succ(Array, myobj) myobj = 1:2 expect_fail(Array, myobj) x = array(dim = c(2, 3)) expect_true(testArray(x)) expect_true(testArray(x, d = 2L)) expect_false(testArray(x, d = 1L)) expect_true(testArray(x, min.d = 0L)) expect_true(testArray(x, min.d = 1L)) expect_true(testArray(x, max.d = 2L)) expect_true(testArray(x, max.d = 3L)) expect_false(testArray(x, min.d = 3L)) expect_false(testArray(x, max.d = 1L)) x[2,2] = NA expect_true(testMatrix(x)) expect_false(testMatrix(x, any.missing = FALSE)) expect_false(testArray(x, any.missing = FALSE)) expect_error(assertArray(iris)) x = array(1:27, dim = c(3, 3, 3)) expect_true(testArray(x, mode = "integer")) expect_true(testArray(x, mode = "numeric")) expect_true(testArray(x, mode = "atomic")) expect_false(testArray(x, mode = "double")) expect_false(testArray(x, mode = "character")) expect_false(testArray(x, mode = "list")) x = array(list(1, 1), dim = c(1, 2)) expect_true(testArray(x)) expect_true(testArray(x, mode = "list")) expect_false(testArray(x, mode = "atomic")) expect_false(testArray(x, mode = "numeric")) expect_error(assertArray(1:3), "array") }) test_that("type guessing works", { x = array(1:4) expect_match(checkCharacter(x), "array") x = array(1:4, dim = c(2, 2)) expect_match(checkCharacter(x), "matrix") x = array(1:9, dim = c(3, 3, 3)) expect_match(checkCharacter(x), "array") }) checkmate/tests/testthat/test_anyInfinite.r0000644000175100001440000000141112514153643020716 0ustar hornikuserscontext("anyInfinite") test_that("anyInfinite", { xb = logical(10) xi = integer(10) xd = double(10) xc = complex(10) xl = as.list(1:10) xm = matrix(1:9, 3) xf = data.frame(a=1:5, b=1:5) expect_false(anyInfinite(NULL)) expect_false(anyInfinite(mean)) expect_false(anyInfinite(double(0))) expect_false(anyInfinite(xb)) expect_false(anyInfinite(xi)) expect_false(anyInfinite(xd)) expect_false(anyInfinite(xc)) expect_false(anyInfinite(xl)) expect_false(anyInfinite(xm)) expect_false(anyInfinite(xf)) xd[5] = xc[5] = xf$b[3] = Inf xl[5] = -Inf expect_true(anyInfinite(xd)) expect_true(anyInfinite(xc)) expect_true(anyInfinite(xl)) expect_true(anyInfinite(xf)) x = list(1, list(1, list(1, Inf))) expect_true(anyInfinite(x)) }) checkmate/tests/testthat/test_checkNames.r0000644000175100001440000000247312514153643020513 0ustar hornikuserscontext("checkNames") test_that("checkNames", { nn = letters[1:3] expect_succ(Names, nn) expect_fail(Names, nn, type = "unnamed") expect_true(testNames(character(0))) expect_false(testNames(NULL)) expect_false(testNames(integer(0))) x = c("a", ".a") expect_true(testNames(x)) expect_true(testNames(x, "unique")) expect_true(testNames(x, "strict")) expect_false(testNames(1)) expect_false(testNames(NA_character_)) expect_false(testNames(NA_integer_)) expect_false(testNames("")) x = c("a", "a") expect_true(testNames(x)) expect_false(testNames(x, "unique")) expect_true(testNames("x", type = "strict")) expect_true(testNames("..x", type = "strict")) expect_true(testNames("x_1", type = "strict")) expect_true(testNames("x.", type = "strict")) expect_false(testNames("1", type = "strict")) expect_false(testNames(".1", type = "strict")) expect_false(testNames("..1", type = "strict")) expect_false(testNames("x ", type = "strict")) expect_false(testNames("ä", type = "strict")) expect_error(assertNames(c("a", "a"), "unique"), "unique") x = c("a", "1") expect_error(assertNames(x, "strict"), "naming rules") }) test_that("argument 'type' is checked", { expect_error(checkNames("x", type = 1), "string") expect_error(checkNames("x", type = NA_character_), "missing") }) checkmate/tests/testthat/test_checkEnvironment.r0000644000175100001440000000117112514153643021746 0ustar hornikuserscontext("checkEnvironment") test_that("checkEnvironment", { myobj = new.env() expect_succ(Environment, myobj) myobj = list() expect_fail(Environment, myobj) ee = new.env(parent = emptyenv()) ee$yyy = 1 ee$zzz = 1 expect_false(testEnvironment(NULL)) expect_false(testEnvironment(list())) expect_true(testEnvironment(ee)) expect_false(testEnvironment(ee, contains = "xxx")) expect_true(testEnvironment(ee, contains = "yyy")) expect_true(testEnvironment(ee, contains = c("yyy", "zzz"))) expect_error(assertEnvironment(list()), "environment") expect_error(assertEnvironment(ee, "xxx"), "with name") }) checkmate/tests/testthat/test_assert.r0000644000175100001440000000152212536305345017747 0ustar hornikuserscontext("assert") test_that("assert", { x = NULL expect_true(assert(checkNull(x), checkDataFrame(x))) grepme = iris expect_true(assert(checkNull(grepme), checkDataFrame(grepme))) expect_error(assert(checkNull(grepme), checkNumeric(grepme)), "One of") expect_error(assert(checkNull(grepme), checkNumeric(grepme)), "grepme") x = 1 expect_true(assert(checkNumeric(x), checkCount(x))) expect_true(assert(checkNumeric(x), checkCount(x), combine = "or")) expect_true(assert(checkNumeric(x), checkCount(x), combine = "and")) x = 1.1 expect_true(assert(checkNumeric(x), checkCount(x), combine = "or")) expect_error(assert(checkNumeric(x), checkCount(x), combine = "and")) x = "a" expect_error(assert(checkNumeric(x), checkCount(x), combine = "or")) expect_error(assert(checkNumeric(x), checkCount(x), combine = "and")) }) checkmate/tests/testthat/test_checkNumeric.r0000644000175100001440000000302312514153643021042 0ustar hornikuserscontext("checkNumeric") test_that("checkNumeric", { myobj = 1 expect_succ(Numeric, myobj) myobj = "a" expect_fail(Numeric, myobj) expect_true(testNumeric(integer(0))) expect_false(testNumeric(NULL)) expect_true(testNumeric(TRUE)) expect_true(testNumeric(NA_character_)) expect_true(testNumeric(NA_real_)) expect_true(testNumeric(NaN)) expect_false(testNumeric(NA_real_, any.missing = FALSE)) expect_false(testNumeric(NA_real_, all.missing = FALSE)) expect_false(testNumeric(NaN, any.missing = FALSE)) expect_false(testNumeric(NaN, all.missing = FALSE)) expect_true(testNumeric(1L)) expect_true(testNumeric(1)) expect_true(testNumeric(Inf)) expect_true(testNumeric(-Inf)) expect_true(assertNumeric(1:2, finite = TRUE)) expect_error(assertNumeric(c(1, Inf), finite = TRUE), "finite") expect_error(assertNumeric(c(1, -Inf), finite = TRUE), "finite") expect_true(testNumeric(1:3, any.missing=FALSE, min.len=1L, max.len=3L)) expect_false(testNumeric(1:3, any.missing=FALSE, len=5)) expect_true(testNumeric(1:3, lower = 1L, upper = 3L)) expect_false(testNumeric(1:3, lower = 5)) expect_error(assertNumeric("a"), "numeric") }) test_that("bounds are checked", { expect_error(checkNumeric(1, lower = "a"), "number") expect_error(checkNumeric(1, lower = 1:2), "number") expect_error(checkNumeric(1, lower = NA_real_), "missing") expect_error(checkNumeric(1, upper = "a"), "number") expect_error(checkNumeric(1, upper = 1:2), "number") expect_error(checkNumeric(1, upper = NA_real_), "missing") }) checkmate/tests/testthat/test_checkInt.r0000644000175100001440000000065412514153643020201 0ustar hornikuserscontext("checkInt") test_that("checkInt", { myobj = 1L expect_succ(Int, myobj) myobj = 1.1 expect_fail(Int, myobj) expect_false(testInt(integer(0))) expect_false(testInt(NULL)) expect_true(testInt(1L)) expect_true(testInt(1.)) expect_false(testInt(NA)) expect_true(testInt(NA_real_, na.ok = TRUE)) expect_false(testInt(1:2)) expect_false(testInt("")) expect_error(assertInt(2+3i), "integerish") }) checkmate/tests/testthat/test_anyMissing.r0000644000175100001440000000401212524117441020557 0ustar hornikuserscontext("anyMissing") xb = logical(10) xi = integer(10) xd = double(10) xc = complex(10) xs = letters[1:10] xl = as.list(1:10) xm = matrix(1:9, 3) xf = data.frame(a=1:5, b=1:5) test_that("anyMissing", { expect_false(anyMissing(integer(0))) expect_false(anyMissing(xb)) expect_false(anyMissing(xi)) expect_false(anyMissing(xd)) expect_false(anyMissing(xc)) expect_false(anyMissing(xs)) expect_false(anyMissing(xl)) expect_false(anyMissing(xm)) expect_false(anyMissing(xf)) xb[5] = xi[5] = xd[5] = xc[5] = xs[5] = xm[2, 2] = xf$b[3] = NA xl[5] = list(NULL) expect_true(anyMissing(xb)) expect_true(anyMissing(xi)) expect_true(anyMissing(xd)) expect_true(anyMissing(xc)) expect_true(anyMissing(xs)) expect_true(anyMissing(xl)) expect_true(anyMissing(xm)) expect_true(anyMissing(xf)) expect_false(anyMissing(as.raw(1))) expect_false(anyMissing(NULL)) expect_error(anyMissing(as.symbol("a")), "supported") }) test_that("allMissing", { expect_true(allMissing(integer(0))) expect_false(allMissing(xb)) expect_false(allMissing(xi)) expect_false(allMissing(xd)) expect_false(allMissing(xc)) expect_false(allMissing(xs)) expect_false(allMissing(xl)) expect_false(allMissing(xm)) expect_false(allMissing(xf)) xb[5] = xi[5] = xd[5] = xc[5] = xm[2, 2] = xf$b[3] = NA xl[5] = list(NULL) expect_false(allMissing(xb)) expect_false(allMissing(xi)) expect_false(allMissing(xd)) expect_false(allMissing(xc)) expect_false(allMissing(xs)) expect_false(allMissing(xl)) expect_false(allMissing(xm)) expect_false(allMissing(xf)) xb[] = xi[] = xd[] = xc[] = xm[] = xs = NA xl = list(NULL, NULL) xf$a = xf$b = NA expect_true(allMissing(xb)) expect_true(allMissing(xi)) expect_true(allMissing(xd)) expect_true(allMissing(xc)) expect_true(allMissing(xs)) expect_true(allMissing(xl)) expect_true(allMissing(xm)) expect_true(allMissing(xf)) expect_false(allMissing(as.raw(1))) expect_false(allMissing(NULL)) expect_error(allMissing(as.symbol("a")), "supported") }) checkmate/tests/testthat/test_checkSubset.r0000644000175100001440000000125512514153643020712 0ustar hornikuserscontext("checkSubset") test_that("checkSubset", { myobj = letters[1:3] expect_succ(Subset, myobj, letters) myobj = 1:2 expect_fail(Subset, myobj, letters) expect_false(testSubset(character(0), letters, empty.ok = FALSE)) expect_true(testSubset(character(0), letters, empty.ok = TRUE)) expect_false(testSubset(NULL, letters, empty.ok = FALSE)) expect_true(testSubset(NULL, letters, empty.ok = TRUE)) expect_true(testSubset(1L, 1:10)) expect_true(testSubset(3:4, 1:10)) expect_false(testSubset("ab", letters)) expect_false(testSubset(NA_integer_, 1:10)) expect_error(assertSubset(-1, 1:2), "subset of") expect_error(assertSubset(1L, list()), "atomic") }) checkmate/tests/testthat/test_checkChoice.R0000644000175100001440000000113312514153643020572 0ustar hornikuserscontext("checkChoice") test_that("checkChoice", { myobj = 1 expect_succ(Choice, myobj, 1:3) myobj = 0 expect_fail(Choice, myobj, 1:3) expect_false(testChoice(character(0), letters)) expect_false(testChoice(NULL, letters)) expect_false(testChoice(1, NULL)) expect_error(testChoice(list(1), as.list(iris)), "atomic") expect_true(testChoice(1L, 1:10)) expect_false(testChoice("ab", letters)) expect_false(testChoice(NA_integer_, 1:10)) expect_false(testChoice(1:2, 1:10)) expect_error(assertChoice(-1, 1:2), "element of") expect_error(assertChoice(1L, list()), "atomic") }) checkmate/tests/testthat/test_checkNumber.r0000644000175100001440000000136412514153643020676 0ustar hornikuserscontext("checkNumber") test_that("checkNumber", { myobj = 1 expect_succ(Number, myobj) myobj = "a" expect_fail(Number, myobj) expect_false(testNumber(integer(0))) expect_false(testNumber(NULL)) expect_true(testNumber(1L)) expect_true(testNumber(1.)) expect_false(testNumber(NA)) expect_false(testNumber(NaN)) expect_true(testNumber(NaN, na.ok = TRUE)) expect_true(testNumber(NA_real_, na.ok = TRUE)) expect_false(testNumber(1:2)) expect_false(testNumber("")) expect_true(testNumber(Inf)) expect_true(testNumber(-Inf)) expect_error(assertNumber(Inf, finite = TRUE), "finite") expect_error(assertNumber(-Inf, finite = TRUE), "finite") expect_false(testNumber(TRUE)) expect_error(assertNumber(2+3i), "number") }) checkmate/tests/testthat/test_deparse.r0000644000175100001440000000034212514153643020066 0ustar hornikuserscontext("deparse") test_that("deparse", { f = function(num, na.ok) { assertNumber(num) qassert(na.ok, "B1") } expect_true(f(1, TRUE)) expect_error(f(NULL, TRUE), "num") expect_error(f(1, NULL), "na.ok") }) checkmate/tests/testthat/test_checkFilesystem.r0000644000175100001440000000434312514153643021572 0ustar hornikuserscontext("checkFile") td = tempfile("checkFile") dir.create(td, recursive=TRUE) fn = file.path(td, "myfile") dn = file.path(td, "dir") ff = file.path(td, "xxx") file.create(fn) dir.create(dn) test_that("check_file", { myobj = fn expect_succ(File, myobj) myobj = ff expect_fail(File, myobj) expect_false(testFile(character(0))) expect_false(testFile(NULL)) expect_false(testFile(dn)) expect_error(assertFile(character(0)), "provided") expect_error(assertFile(ff), "exist") expect_error(assertFile(dn)) }) test_that("check_directory", { myobj = dn expect_succ(Directory, myobj) myobj = ff expect_fail(Directory, myobj) expect_false(testDirectory(character(0))) expect_false(testDirectory(fn)) expect_error(assertDirectory(character(0)), "provided") expect_error(assertDirectory(ff), "exist") expect_error(assertDirectory(fn)) }) test_that("check_access", { myobj = R.home() expect_succ(Access, myobj, "r") if (.Platform$OS.type != "windows") { Sys.chmod(fn, "0000") expect_true(testAccess(fn, "")) expect_false(testAccess(fn, "r")) expect_false(testAccess(fn, "w")) expect_false(testAccess(fn, "x")) Sys.chmod(fn, "0700") expect_true(testAccess(fn, "")) expect_true(testAccess(fn, "r")) expect_true(testAccess(fn, "w")) expect_true(testAccess(fn, "x")) Sys.chmod(fn, "0600") expect_true(testAccess(fn, "")) expect_true(testAccess(fn, "r")) expect_true(testAccess(fn, "rw")) expect_false(testAccess(fn, "rx")) expect_false(testAccess(fn, "wx")) expect_error(testAccess(fn, "a")) expect_error(testAccess(fn, "rrr")) } }) test_that("check_path_for_output", { myobj = ff expect_succ(PathForOutput, myobj) myobj = fn expect_fail(PathForOutput, myobj) expect_false(testPathForOutput(character(0))) expect_false(testPathForOutput(NULL)) expect_error(assertPathForOutput(character(0)), "path provided") expect_true(assertPathForOutput(c("a", "b")), "path") expect_true(assertPathForOutput(ff)) expect_error(assertPathForOutput(fn), "exist") expect_true(assertPathForOutput(fn, overwrite = TRUE)) expect_true(testPathForOutput(c(fn, ff, dn), overwrite = TRUE)) expect_false(testPathForOutput(c(fn, ff, dn), overwrite = FALSE)) }) checkmate/tests/testthat/test_checkFunction.r0000644000175100001440000000252512514153643021233 0ustar hornikuserscontext("checkFunction") test_that("checkFunction", { myobj = mean expect_succ(Function, myobj) myobj = TRUE expect_fail(Function, myobj) myfun = function(x, y, ...) x + y expect_false(testFunction(NULL)) expect_true(testFunction(identity)) expect_true(testFunction(myfun)) # expect_true(testFunction("myfun")) expect_false(testFunction(fff)) expect_false(testFunction("fff")) expect_true(testFunction(myfun, args = "x")) expect_true(testFunction(myfun, args = "...")) expect_true(testFunction(myfun, args = "x", ordered=TRUE)) expect_true(testFunction(myfun, args = "y")) expect_true(testFunction(myfun, args = c("x", "y"))) expect_true(testFunction(myfun, args = c("x", "y", "..."))) expect_true(testFunction(myfun, args = c("y", "x"))) expect_true(testFunction(myfun, args = c("x", "y"), ordered=TRUE)) expect_false(testFunction(myfun, args = "z")) expect_false(testFunction(myfun, args = c("y"), ordered=TRUE)) expect_false(testFunction(myfun, args = c("y", "x"), ordered=TRUE)) expect_error(assertFunction(fff), "not found") expect_error(assertFunction(myfun, "z"), "formal arguments") expect_error(assertFunction(myfun, "y", ordered=TRUE), "first formal arguments") expect_false(testFunction(function(x) x^2, args = character(0))) expect_true(testFunction(function() x^2, args = character(0))) }) checkmate/tests/testthat/test_checkNull.r0000644000175100001440000000036212514153643020355 0ustar hornikuserscontext("checkNull") test_that("checkNull", { myobj = NULL expect_succ(Null, myobj) myobj = TRUE expect_fail(Null, myobj) expect_false(testNull(integer(0))) expect_true(testNull(NULL)) expect_error(assertNull(-1), "NULL") }) checkmate/tests/testthat/test_checkScalar.r0000644000175100001440000000067212514153643020654 0ustar hornikuserscontext("checkScalar") test_that("checkScalar", { myobj = "a" expect_succ(Scalar, myobj) myobj = 1:2 expect_fail(Scalar, myobj) expect_true(testScalar(TRUE)) expect_true(testScalar(1L)) expect_true(testScalar(1)) expect_true(testScalar(1+1i)) expect_false(testScalar(list(1))) expect_false(testScalar(NA, na.ok = FALSE)) expect_true(testScalar(NA, na.ok = TRUE)) expect_error(assertScalar(integer(0)), "scalar") }) checkmate/tests/testthat/test_checkString.r0000644000175100001440000000075712514153643020721 0ustar hornikuserscontext("checkString") test_that("checkString", { myobj = "a" expect_succ(String, myobj) myobj = 1L expect_fail(String, myobj) expect_false(testString(character(0))) expect_false(testString(NULL)) expect_true(testString("")) expect_true(testString("foo")) expect_true(testString(NA, na.ok = TRUE)) expect_false(testString(NA_character_)) expect_true(testString(NA_character_, na.ok = TRUE)) expect_true(testString(NA, na.ok = TRUE)) expect_error(assertString(1)) }) checkmate/tests/testthat/test_qtest.r0000644000175100001440000001276512514153643017617 0ustar hornikuserscontext("qtest") xb = logical(10); xb[5] = NA xi = integer(10); xi[5] = NA xr = double(10); xr[5] = NA xc = complex(10); xc[5] = NA xl = as.list(1:10); xl[5] = list(NULL) xm = matrix(1:9, 3); xm[2, 3] = NA xd = data.frame(a=1:5, b=1:5); xd$b[3] = NA xe = new.env(); xe$foo = 1 xf = function(x) x expect_succ = function(x, rules) { expect_true(qtest(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) expect_true(qassert(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) } expect_fail = function(x, rules) { expect_false(qtest(x, rules), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) expect_true(inherits(try(qassert(x, rules), silent=TRUE), "try-error"), info=sprintf("vector %s, rules: %s", deparse(substitute(x)), paste(rules, collapse=","))) } test_that("type and missingness", { expect_succ(xb, "b") expect_fail(xb, "B") expect_succ(xi, "i") expect_fail(xi, "I") expect_succ(xr, "r") expect_fail(xr, "R") expect_succ(xc, "c") expect_fail(xc, "C") expect_succ(xl, "l") expect_fail(xl, "L") expect_succ(xm, "m") expect_fail(xm, "M") expect_succ(xd, "d") expect_fail(xd, "D") expect_succ(xe, "e") expect_succ(xf, "f") expect_fail(xd, "b") expect_fail(xd, "i") expect_fail(xd, "r") expect_fail(xd, "c") expect_fail(xd, "l") expect_fail(xd, "m") expect_fail(xl, "e") expect_fail(xm, "r") expect_fail(xl, "d") expect_fail(xl, "f") }) test_that("integerish", { expect_succ(xb, "x") expect_succ(xi, "x") expect_succ(xi, "x") expect_fail(xi, "X") expect_succ(xr, "x") expect_fail(xr, "X") expect_fail(1:3+.0001, "x") expect_fail(xd, "x") }) test_that("length", { expect_succ(xb, "b+") expect_succ(xb, "b10") expect_succ(logical(1), "b+") expect_succ(logical(1), "b?") expect_succ(logical(1), "b1") expect_fail(xb, "b?") expect_fail(xb, "b5") expect_fail(xb, "b>=50") expect_succ(xb, "b<=50") expect_succ(xe, "e1") expect_fail(xe, "e>=2") expect_fail(xe, "f+") }) test_that("bounds", { xx = 1:3 expect_succ(xx, "i+[1,3]") expect_succ(xx, "i+(0,4)") expect_succ(xx, "i+(0.9999,3.0001)") expect_succ(xx, "i+(0,1e2)") expect_fail(xx, "i+(1,3]") expect_fail(xx, "i+[1,3)") expect_succ(1, "n[0, 100]") expect_succ(xx, "i[1,)") expect_succ(xx, "i[,3]") expect_succ(Inf, "n(1,]") expect_succ(-Inf, "n[,1]") expect_succ(c(-Inf, 0, Inf), "n[,]") expect_fail(Inf, "n(1,)") expect_fail(-Inf, "n(,0]") expect_fail(c(-Inf, 0, Inf), "n(,]") expect_fail(c(-Inf, 0, Inf), "n(,)") expect_succ(1, "n+()") expect_succ(1, "n+[]") expect_succ(Inf, "n+[]") expect_succ(Inf, "n+(]") expect_succ(-Inf, "n+[)") expect_fail(Inf, "n+()") expect_fail(Inf, "n+[)") expect_fail(-Inf, "n+(]") }) test_that("non-atomic types", { expect_succ(function() 1, "*") expect_fail(function() 1, "b") expect_succ(function() 1, "*") expect_succ(NULL, "0?") expect_fail(xi, "0") expect_fail(NULL, "0+") expect_succ(NULL, "00") expect_fail(xe, "b") expect_fail(xf, "b") expect_fail(as.symbol("x"), "n") expect_fail(xd, "a") }) test_that("atomic types", { expect_succ(NULL, "a") expect_succ(xb, "a+") expect_fail(xb, "A+") expect_succ(xi, "a+") expect_fail(xi, "A+") expect_succ(xi, "n+") expect_fail(xi, "N+") expect_succ(xr, "n+") expect_fail(xr, "N+") expect_succ(xr, "a+") expect_fail(xr, "A+") expect_succ(xm, "a+") expect_fail(xm, "A+") expect_fail(xl, "a+") expect_fail(xl, "A+") expect_fail(xe, "a+") expect_fail(xf, "a+") expect_fail(NULL, "v") expect_succ(xb, "v+") expect_fail(xb, "V+") expect_succ(xi, "v+") expect_fail(xi, "V+") expect_succ(xr, "v+") expect_fail(xr, "V+") expect_succ(xm, "v+") expect_fail(xm, "V+") expect_fail(xl, "v+") expect_fail(xl, "V+") expect_fail(xe, "v+") expect_fail(xf, "V+") }) test_that("optional chars", { expect_succ(TRUE, "b*") expect_succ(TRUE, "b=1") expect_succ(TRUE, "b>=0") expect_succ(TRUE, "b>0") expect_succ(TRUE, "b<2") expect_fail(TRUE, "b=2") expect_fail(TRUE, "b>=2") expect_fail(TRUE, "b>2") expect_fail(TRUE, "b<0") }) test_that("malformated pattern", { expect_error(qassert(1, ""), "[Ee]mpty") # expect_warning(expect_error(qassert(1, "ä")), "locale") expect_error(qassert(1, "nn"), "length definition") expect_error(qassert(1, "n="), "length definition") expect_error(qassert(1, "n=="), "length definition") expect_error(qassert(1, "n==="), "length definition") expect_error(qassert(1, "n?1"), "bound definition") expect_error(qassert(1, "n>")) expect_error(qassert(1, "nö")) expect_error(qassert(1, "n\n")) expect_error(qassert(1, "n+a"), "opening") expect_error(qassert(1, "n+["), "bound") expect_error(qassert(1, "n+[1"), "lower") expect_error(qassert(1, "n+[x,]"), "lower") expect_error(qassert(1, "n+[,y]"), "upper") expect_error(qassert(1, "n*("), "bound definition") expect_error(qassert(1, "n*]"), "bound definition") }) test_that("we get some output", { expect_error(qassert(1, "b"), "logical") expect_error(qassert(1, "l"), "list") expect_error(qassert(1:2, "n?"), "length <=") }) test_that("empty vectors", { expect_succ(integer(0), "i*") expect_succ(integer(0), "i*[0,0]") expect_succ(integer(0), "n[0,0]") expect_fail(integer(0), "r[0,0]") expect_fail(integer(0), "*+") }) test_that("logicals are not numeric", { expect_fail(TRUE, "i") expect_fail(TRUE, "I") expect_fail(TRUE, "n") expect_fail(TRUE, "N") }) checkmate/tests/testthat/test_checkMatrix.r0000644000175100001440000000610312524351516020706 0ustar hornikuserscontext("checkMatrix") test_that("checkMatrix", { myobj = matrix(1:9, 3) expect_succ(Matrix, myobj) myobj = TRUE expect_fail(Matrix, myobj) x = matrix(1:9, 3) expect_true(testMatrix(x)) expect_true(testMatrix(matrix(nrow=0, ncol=0))) expect_false(testMatrix(NULL)) x[2,2] = NA expect_true(testMatrix(x)) expect_false(testMatrix(x, any.missing = FALSE)) xl = matrix(TRUE) xi = matrix(1L) xr = matrix(1.) xs = matrix("a") xc = matrix(1+1i) xx = array(list(1, 1), dim = c(1, 2)) xe = matrix(nrow = 0, ncol = 0); storage.mode(xe) = "double" expect_true(testMatrix(xl, "logical")) expect_true(testMatrix(xi, "integer")) expect_true(testMatrix(xr, "double")) expect_true(testMatrix(xe, "double")) expect_true(testMatrix(xr, "numeric")) expect_true(testMatrix(xc, "complex")) expect_true(testMatrix(xs, "character")) expect_true(testMatrix(xx, "list")) expect_false(testMatrix(xs, "logical")) expect_false(testMatrix(xs, "integer")) expect_false(testMatrix(xs, "double")) expect_false(testMatrix(xe, "logical")) expect_false(testMatrix(xs, "numeric")) expect_false(testMatrix(xs, "complex")) expect_false(testMatrix(xl, "character")) expect_false(testMatrix(xx, "numeric")) expect_false(testMatrix(xx, "atomic")) expect_true(testMatrix(x, min.rows = 1, min.cols = 1)) expect_true(testMatrix(x, nrows = 3, ncols = 3)) expect_true(testMatrix(xx, nrows = 1, ncols = 2)) expect_true(testMatrix(xe, nrows = 0, ncols = 0)) expect_false(testMatrix(x, min.rows = 5)) expect_false(testMatrix(x, min.cols = 5)) expect_false(testMatrix(x, nrows = 5)) expect_false(testMatrix(x, ncols = 5)) expect_false(testMatrix(x, row.names = "named")) expect_false(testMatrix(x, col.names = "named")) rownames(x) = letters[1:3]; colnames(x) = NULL expect_true(testMatrix(x, row.names = "named")) expect_false(testMatrix(x, col.names = "named")) colnames(x) = letters[1:3]; rownames(x) = NULL expect_false(testMatrix(x, row.names = "named")) expect_true(testMatrix(x, col.names = "named")) colnames(x) = rownames(x) = letters[1:3] expect_true(testMatrix(x, row.names = "named")) expect_true(testMatrix(x, col.names = "named")) # named and unnamed is the same for "empty" matricies expect_true(testMatrix(xe, row.names = "unnamed")) expect_true(testMatrix(xe, col.names = "unnamed")) expect_true(testMatrix(xe, row.names = "strict")) expect_true(testMatrix(xe, col.names = "strict")) expect_error(assertMatrix(iris), "matrix") expect_error(assertMatrix(matrix(), min.rows = 99), "99") }) test_that("dimension arugments are checked", { x = matrix(1) expect_error(checkMatrix(x, min.rows = 1.2), "count") expect_error(checkMatrix(x, min.rows = NA_integer_), "missing") expect_error(checkMatrix(x, min.rows = -1), ">= 0") }) test_that("dimensions are reported correctly", { x = matrix(1:42, ncol = 1) expect_true(grepl(42, checkMatrix(x, nrows = 43))) expect_true(grepl(42, checkMatrix(x, min.rows = 43))) x = t(x) expect_true(grepl(42, checkMatrix(x, ncols = 43))) expect_true(grepl(42, checkMatrix(x, min.cols = 43))) }) checkmate/tests/testthat/test_checkCharacter.r0000644000175100001440000000263712514153643021346 0ustar hornikuserscontext("checkCharacter") test_that("checkCharacter", { myobj = c("a", "b") expect_succ(Character, myobj) myobj = 0 expect_fail(Character, myobj) expect_true(testCharacter(character(0))) expect_false(testCharacter(NULL)) expect_true(testCharacter("a")) expect_false(testCharacter(1)) expect_true(testCharacter(NA)) expect_true(testCharacter(NA_character_)) expect_true(testCharacter("a", min.chars = 1)) expect_false(testCharacter("a", min.chars = 2)) # treat NA_character_ as zero-length string expect_true(testCharacter(NA_character_, min.chars = 0)) expect_false(testCharacter(NA_character_, min.chars = 1)) x = c("abba", "baab") expect_true(testCharacter(x, pattern="a")) expect_true(testCharacter(x, pattern="ab")) expect_false(testCharacter(x, pattern="aa")) expect_false(testCharacter(x, pattern="^ab")) expect_true(testCharacter(x, pattern="AB", ignore.case=TRUE)) expect_true(testCharacter(x, pattern="AB", ignore.case=TRUE)) expect_false(testCharacter(x, pattern="AB", ignore.case=FALSE)) expect_false(testCharacter(x, pattern="AB", ignore.case=FALSE)) expect_true(testCharacter(x, pattern="a+", fixed=FALSE)) expect_false(testCharacter(x, pattern="a+", fixed=TRUE)) x = letters[1:3] expect_true(testCharacter(x, any.missing=FALSE, min.len=1L, max.len=3L)) expect_false(testCharacter(x, any.missing=FALSE, len=5)) expect_error(assertCharacter(1), "character") }) checkmate/tests/testthat/helper.r0000644000175100001440000000130412514153643016662 0ustar hornikusersexpect_succ = function(part, x, ...) { part = as.character(substitute(part)) fun = match.fun(paste0("check", part)) expect_true(fun(x, ...)) fun = match.fun(paste0("test", part)) expect_true(fun(x, ...)) fun = match.fun(paste0("assert", part)) expect_true(fun(x, ...)) invisible(TRUE) } expect_fail = function(part, x, ...) { part = as.character(substitute(part)) xn = deparse(substitute(x)) fun = match.fun(paste0("check", part)) expect_true(testString(fun(x, ...))) fun = match.fun(paste0("test", part)) expect_false(fun(x, ...)) fun = match.fun(paste0("assert", part)) expect_error(fun(x, ..., .var.name = xn), xn) expect_error(fun(x, ...), "'x'") invisible(TRUE) } checkmate/tests/testthat/test_checkIntegerish.r0000644000175100001440000000265512514153643021553 0ustar hornikuserscontext("checkIntegerish") test_that("checkIntegerish", { myobj = 1 expect_succ(Integerish, myobj) myobj = 3.3 expect_fail(Integerish, myobj) x = 1 - 0.9 -.1 expect_true(testIntegerish(integer(0))) expect_false(testIntegerish(NULL)) expect_true(testIntegerish(TRUE)) expect_true(testIntegerish(FALSE)) expect_true(testIntegerish(1L)) expect_true(testIntegerish(c(-1, 0, 1))) expect_true(testIntegerish(1.)) expect_true(testIntegerish(x)) expect_true(testIntegerish(NA)) expect_true(testIntegerish(NaN)) expect_true(testIntegerish(c(1L, NA))) expect_true(testIntegerish(c(1, NA))) expect_true(testIntegerish(c(1, NaN))) expect_false(testIntegerish(1:2 + 0.0001)) expect_false(testIntegerish(-Inf)) expect_false(testIntegerish(Inf)) expect_true(testIntegerish(3+0i)) expect_false(testIntegerish(3-1i)) expect_true(testIntegerish(as.complex(NA))) expect_false(testIntegerish(3+2i)) expect_false(testIntegerish(list())) max = as.double(.Machine$integer.max) min = as.double(-.Machine$integer.max) expect_true(testIntegerish(min)) expect_true(testIntegerish(max)) expect_false(testIntegerish(min-1)) expect_false(testIntegerish(max+1)) expect_false(testIntegerish(min-.1)) expect_false(testIntegerish(max+.1)) expect_false(testIntegerish(NA, any.missing = FALSE)) expect_false(testIntegerish(NA, all.missing = FALSE)) expect_error(assertIntegerish(x, tol=0), "integerish") }) checkmate/tests/testthat/test_checkInteger.r0000644000175100001440000000135612524117441021041 0ustar hornikuserscontext("checkInteger") test_that("checkInteger", { myobj = 1L expect_succ(Integer, myobj) myobj = 1 expect_fail(Integer, myobj) expect_true(testInteger(integer(0))) expect_false(testInteger(NULL)) expect_false(testInteger(TRUE)) expect_true(testInteger(NA)) expect_false(testInteger(NA, any.missing = FALSE)) expect_false(testInteger(NA, all.missing = FALSE)) expect_true(testInteger(1L)) expect_true(testInteger(1:3, any.missing = FALSE, min.len = 1L, max.len = 3L)) expect_false(testInteger(1:3, any.missing = FALSE, len = 5)) expect_true(testInteger(1:3, lower = 1L, upper = 3L)) expect_false(testInteger(1:3, lower = 5)) expect_false(testInteger(1:3, upper = 1)) expect_error(assertInteger(1), "integer") }) checkmate/src/0000755000175100001440000000000012540757715013020 5ustar hornikuserscheckmate/src/which_first.c0000644000175100001440000000126112540757715015475 0ustar hornikusers#include "which_first.h" SEXP c_which_first(SEXP x) { if (!isLogical(x)) error("Argument 'x' must be logical"); const R_xlen_t n = xlength(x); const int *xp = LOGICAL(x); for (R_xlen_t i = 0; i < n; i++) { if (xp[i] != NA_LOGICAL && xp[i]) return ScalarInteger(i+1); } return allocVector(INTSXP, 0); } SEXP c_which_last(SEXP x) { if (!isLogical(x)) error("Argument 'x' must be logical"); const R_xlen_t n = xlength(x); const int *xp = LOGICAL(x); for (R_xlen_t i = n - 1; i >= 0; i--) { if (xp[i] != NA_LOGICAL && xp[i]) return ScalarInteger(i+1); } return allocVector(INTSXP, 0); } checkmate/src/any_infinite.h0000644000175100001440000000030412540757715015642 0ustar hornikusers#ifndef CHECKMATE_ANY_INFINITE_H_ #define CHECKMATE_ANY_INFINITE_H_ #include #define USE_RINTERNALS #include SEXP c_any_infinite(SEXP); Rboolean any_infinite(SEXP); #endif checkmate/src/helper.h0000644000175100001440000000060712540757715014453 0ustar hornikusers#ifndef CHECKMATE_HELPER_H_ #define CHECKMATE_HELPER_H_ #include #define USE_RINTERNALS #include Rboolean isStrictlyNumeric(SEXP); Rboolean isRList(SEXP); R_len_t get_ncols(SEXP); R_len_t get_nrows(SEXP); double asNumber(SEXP, const char *); const char * asString(SEXP, const char *); R_xlen_t asCount(SEXP, const char *); Rboolean asFlag(SEXP, const char *); #endif checkmate/src/helper.c0000644000175100001440000000522712540757715014451 0ustar hornikusers#include "helper.h" #include "any_missing.h" #include "is_integerish.h" Rboolean isStrictlyNumeric(SEXP x) { switch(TYPEOF(x)) { case REALSXP: return TRUE; case INTSXP: return !inherits(x, "factor"); } return FALSE; } /* Checks for a regular list, i.e. not a data frame, not NULL */ Rboolean isRList(SEXP x) { if (TYPEOF(x) == VECSXP) { SEXP cl = getAttrib(x, R_ClassSymbol); const R_len_t n = length(cl); for (R_len_t i = 0; i < n; i++) { if (strcmp(CHAR(STRING_ELT(cl, i)), "data.frame") == 0) return FALSE; } return TRUE; } return FALSE; } /* ncols and nrows is bugged for data frames: * (a) data.frames are treated like lists and thus you get length() back * (b) reports wrong dimension for zero-column data frames * Here are our own wrappers * */ R_len_t get_nrows(SEXP x) { if (isVector(x) || isList(x)) { if (isFrame(x)) return length(getAttrib(x, R_RowNamesSymbol)); } else { error("Object does not have a dimension"); } SEXP dim = getAttrib(x, R_DimSymbol); if (dim == R_NilValue) return length(x); return INTEGER(dim)[0]; } R_len_t get_ncols(SEXP x) { if (isVector(x) || isList(x)) { if (isFrame(x)) return length(x); SEXP dim = getAttrib(x, R_DimSymbol); if (length(dim) >= 2) return INTEGER(dim)[1]; } else { error("Object does not have a dimension"); } return 1; } double asNumber(SEXP x, const char *vname) { if (!isNumeric(x) || xlength(x) != 1) error("Argument '%s' must be a number", vname); double xd = asReal(x); if (ISNAN(xd)) error("Argument '%s' may not be missing", vname); return xd; } const char * asString(SEXP x, const char *vname) { if (!isString(x) || xlength(x) != 1) error("Argument '%s' must be a string", vname); if (any_missing_string(x)) error("Argument '%s' may not be missing", vname); return CHAR(STRING_ELT(x, 0)); } R_xlen_t asCount(SEXP x, const char *vname) { if (!isIntegerish(x, INTEGERISH_DEFAULT_TOL) || xlength(x) != 1) error("Argument '%s' must be a count", vname); int xi = asInteger(x); if (xi == NA_INTEGER) error("Argument '%s' may not be missing", vname); if (xi < 0) error("Argument '%s' must be >= 0", vname); return xi; } Rboolean asFlag(SEXP x, const char *vname) { if (!isLogical(x) || xlength(x) != 1) error("Argument '%s' must be a flag", vname); Rboolean xb = LOGICAL(x)[0]; if (xb == NA_LOGICAL) error("Argument '%s' may not be missing", vname); return xb; } checkmate/src/is_integerish.h0000644000175100001440000000040512540757715016024 0ustar hornikusers#ifndef CHECKMATE_IS_INTEGERISH_H_ #define CHECKMATE_IS_INTEGERISH_H_ #include #define USE_RINTERNALS #include #define INTEGERISH_DEFAULT_TOL sqrt(DOUBLE_EPS) Rboolean isIntegerish(SEXP, double); SEXP c_is_integerish(SEXP, SEXP); #endif checkmate/src/cmessages.h0000644000175100001440000000066612540757715015153 0ustar hornikusers#ifndef CHECKMATE_CMESSAGES_H_ #define CHECKMATE_CMESSAGES_H_ #include #define USE_RINTERNALS #include enum { CMSGLEN = 256 }; typedef struct { Rboolean ok; char msg[CMSGLEN]; } msg_t; extern const msg_t MSGT; extern const msg_t MSGF; msg_t make_msg(const char *, ...); SEXP make_result(const char *, ...); const char * guessType(SEXP); SEXP make_type_error(SEXP, const char *); SEXP mwrap(msg_t); #endif checkmate/src/any_infinite.c0000644000175100001440000000237612540757715015650 0ustar hornikusers#include "any_infinite.h" static Rboolean any_infinite_double(SEXP x); static Rboolean any_infinite_complex(SEXP x); static Rboolean any_infinite_list(SEXP x); static Rboolean any_infinite_double(SEXP x) { const double * xp = REAL(x); const double * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (*xp == R_PosInf || *xp == R_NegInf) return TRUE; } return FALSE; } static Rboolean any_infinite_complex(SEXP x) { const Rcomplex * xp = COMPLEX(x); const Rcomplex * const xe = xp + xlength(x); for (; xp != xe; xp++) { if ((*xp).r == R_PosInf || (*xp).i == R_PosInf || (*xp).r == R_NegInf || (*xp).i == R_NegInf) return TRUE; } return FALSE; } static Rboolean any_infinite_list(SEXP x) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (any_infinite(VECTOR_ELT(x, i))) return TRUE; } return FALSE; } Rboolean any_infinite(SEXP x) { switch(TYPEOF(x)) { case REALSXP: return any_infinite_double(x); case CPLXSXP: return any_infinite_complex(x); case VECSXP: return any_infinite_list(x); } return FALSE; } SEXP c_any_infinite(SEXP x) { return ScalarLogical(any_infinite(x)); } checkmate/src/all_nchar.h0000644000175100001440000000025212540757715015113 0ustar hornikusers#ifndef CHECKMATE_ALL_NCHAR_H_ #define CHECKMATE_ALL_NCHAR_H_ #include #define USE_RINTERNALS #include Rboolean all_nchar(SEXP, R_xlen_t); #endif checkmate/src/cmessages.c0000644000175100001440000000217312540757715015141 0ustar hornikusers#include "cmessages.h" const msg_t MSGT = { .ok = TRUE }; const msg_t MSGF = { .ok = FALSE }; msg_t make_msg(const char *fmt, ...) { msg_t msg = { .ok = FALSE }; va_list vargs; va_start(vargs, fmt); vsnprintf(msg.msg, CMSGLEN, fmt, vargs); va_end(vargs); return msg; } SEXP make_result(const char *fmt, ...) { char msg[CMSGLEN]; va_list vargs; va_start(vargs, fmt); vsnprintf(msg, CMSGLEN, fmt, vargs); va_end(vargs); return ScalarString(mkChar(msg)); } const char * guessType(SEXP x) { SEXP attr = getAttrib(x, R_ClassSymbol); if (!isNull(attr)) return CHAR(STRING_ELT(attr, 0)); attr = getAttrib(x, R_DimSymbol); if (!isNull(attr) && isVectorAtomic(x)) return length(attr) == 2 ? "matrix" : "array"; return type2char(TYPEOF(x)); } SEXP make_type_error(SEXP x, const char *expected) { char msg[CMSGLEN]; snprintf(msg, CMSGLEN, "Must be of type '%s', not '%s'", expected, guessType(x)); return ScalarString(mkChar(msg)); } SEXP mwrap(msg_t msg) { if (msg.ok) return ScalarLogical(TRUE); return ScalarString(mkChar(msg.msg)); } checkmate/src/all_nchar.c0000644000175100001440000000042212540757715015105 0ustar hornikusers#include "all_nchar.h" Rboolean all_nchar(SEXP x, const R_xlen_t n) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (STRING_ELT(x, i) == NA_STRING || xlength(STRING_ELT(x, i)) < n) return FALSE; } return TRUE; } checkmate/src/any_missing.c0000644000175100001440000000627412540757715015515 0ustar hornikusers#include "any_missing.h" Rboolean any_missing_logical(SEXP x) { const int * xp = LOGICAL(x); const int * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (*xp == NA_LOGICAL) return TRUE; } return FALSE; } Rboolean any_missing_integer(SEXP x) { const int * xp = INTEGER(x); const int * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (*xp == NA_INTEGER) return TRUE; } return FALSE; } Rboolean any_missing_integerish(SEXP x) { switch(TYPEOF(x)) { case LGLSXP: return any_missing_logical(x); case INTSXP: return any_missing_integer(x); case REALSXP: return any_missing_double(x); default: error("Error in any_missing_logical: x is not logical or numeric"); } } Rboolean any_missing_double(SEXP x) { const double * xp = REAL(x); const double * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (ISNAN(*xp)) return TRUE; } return FALSE; } Rboolean any_missing_numeric(SEXP x) { switch(TYPEOF(x)) { case INTSXP: return any_missing_integer(x); case REALSXP: return any_missing_double(x); default: error("Error in any_missing_numeric: x is not integer or double"); } } Rboolean any_missing_complex(SEXP x) { const Rcomplex * xp = COMPLEX(x); const Rcomplex * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (ISNAN((*xp).r) || ISNAN((*xp).i)) return TRUE; } return FALSE; } Rboolean any_missing_string(SEXP x) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (STRING_ELT(x, i) == NA_STRING) return TRUE; } return FALSE; } Rboolean any_missing_atomic(SEXP x) { switch(TYPEOF(x)) { case LGLSXP: return any_missing_logical(x); case INTSXP: return any_missing_integer(x); case REALSXP: return any_missing_double(x); case CPLXSXP: return any_missing_complex(x); case STRSXP: return any_missing_string(x); default: return(FALSE); } } Rboolean any_missing_list(SEXP x) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (isNull(VECTOR_ELT(x, i))) return TRUE; } return FALSE; } Rboolean any_missing_matrix(SEXP x) { return any_missing_atomic(x); } Rboolean any_missing_frame(SEXP x) { const R_xlen_t nc = xlength(x); for (R_xlen_t i = 0; i < nc; i++) { if (any_missing_atomic(VECTOR_ELT(x, i))) return TRUE; } return FALSE; } SEXP c_any_missing(SEXP x) { Rboolean res; switch(TYPEOF(x)) { case LGLSXP: res = any_missing_logical(x); break; case INTSXP: res = any_missing_integer(x); break; case REALSXP: res = any_missing_double(x); break; case CPLXSXP: res = any_missing_complex(x); break; case STRSXP: res = any_missing_string(x); break; case NILSXP: res = FALSE; break; case VECSXP: res = isFrame(x) ? any_missing_frame(x) : any_missing_list(x); break; case RAWSXP: res = FALSE; break; default: error("Object of type '%s' not supported", type2char(TYPEOF(x))); } return ScalarLogical(res); } checkmate/src/which_first.h0000644000175100001440000000032312540757715015500 0ustar hornikusers#ifndef CHECKMATE_WHICH_FIRST_H_ #define CHECKMATE_WHICH_FIRST_H_ #include #define USE_RINTERNALS #include #include SEXP c_which_first(SEXP); SEXP c_which_last(SEXP); #endif checkmate/src/all_missing.h0000644000175100001440000000105212540757715015470 0ustar hornikusers#ifndef CHECKMATE_ALL_MISSING_H_ #define CHECKMATE_ALL_MISSING_H_ #include #define USE_RINTERNALS #include Rboolean all_missing_logical(SEXP); Rboolean all_missing_integer(SEXP); Rboolean all_missing_integerish(SEXP); Rboolean all_missing_double(SEXP); Rboolean all_missing_numeric(SEXP); Rboolean all_missing_complex(SEXP); Rboolean all_missing_string(SEXP); Rboolean all_missing_atomic(SEXP); Rboolean all_missing_list(SEXP); Rboolean all_missing_matrix(SEXP); Rboolean all_missing_frame(SEXP); SEXP c_all_missing(SEXP); #endif checkmate/src/checks.c0000644000175100001440000004662212540757715014436 0ustar hornikusers#include "checks.h" #include #include #include "cmessages.h" #include "is_integerish.h" #include "any_missing.h" #include "any_infinite.h" #include "all_missing.h" #include "all_nchar.h" #include "helper.h" /*********************************************************************************************************************/ /* Some helpers */ /*********************************************************************************************************************/ static inline double asTol(SEXP tol) { return asNumber(tol, "tol"); } static inline Rboolean is_scalar_na(SEXP x) { if (xlength(x) == 1) { switch(TYPEOF(x)) { case LGLSXP: return (LOGICAL(x)[0] == NA_LOGICAL); case INTSXP: return (INTEGER(x)[0] == NA_INTEGER); case REALSXP: return ISNAN(REAL(x)[0]); case STRSXP: return (STRING_ELT(x, 0) == NA_STRING); } } return FALSE; } static inline Rboolean is_vector(SEXP x) { SEXP attr = ATTRIB(x); if (length(attr) > 0 && (TAG(attr) != R_NamesSymbol || CDR(attr) != R_NilValue)) return FALSE; return TRUE; } static msg_t check_bounds(SEXP x, SEXP lower, SEXP upper) { double tmp; tmp = asNumber(lower, "lower"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp < tmp) return make_msg("All elements must be >= %g", tmp); } } else { error("Bound checks only possible for numeric variables"); } } tmp = asNumber(upper, "upper"); if (R_FINITE(tmp)) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && *xp > tmp) return make_msg("All elements must be <= %g", tmp); } } else { error("Bound checks only possible for numeric variables"); } } return MSGT; } /*********************************************************************************************************************/ /* Shared check functions returning an intermediate msg_t */ /*********************************************************************************************************************/ static Rboolean check_valid_names(SEXP x) { return !isNull(x) && !any_missing_string(x) && all_nchar(x, 1); } static Rboolean check_unique_names(SEXP x) { return any_duplicated(x, FALSE) == 0; } static Rboolean check_strict_names(SEXP x) { const R_xlen_t nx = xlength(x); const char *str; for (R_xlen_t i = 0; i < nx; i++) { str = CHAR(STRING_ELT(x, i)); while (*str == '.') str++; if (!isalpha(*str)) return FALSE; for (; *str != '\0'; str++) { if (!isalnum(*str) && *str != '.' && *str != '_') return FALSE; } } return TRUE; } static msg_t check_names(SEXP nn, SEXP type, const char * what) { typedef enum { T_NAMED, T_UNIQUE, T_STRICT } name_t; const char * expected = asString(type, "names"); if (strcmp(expected, "unnamed") == 0) { if (isNull(nn)) return MSGT; return make_msg("%s must be unnamed, but has names", what); } name_t checks; if (strcmp(expected, "named") == 0) { checks = T_NAMED; } else if (strcmp(expected, "unique") == 0) { checks = T_UNIQUE; } else if (strcmp(expected, "strict") == 0) { checks = T_STRICT; } else { error("Unknown type definition '%s'", expected); } if (!check_valid_names(nn)) return make_msg("%s must be named", what); if (checks >= T_UNIQUE) { if (!check_unique_names(nn)) return make_msg("%s must be uniquely named", what); if (checks == T_STRICT && !check_strict_names(nn)) return make_msg("%s must be named according to R's variable naming rules", what); } return MSGT; } static msg_t check_vector_props(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isNull(len)) { R_xlen_t n = asCount(len, "len"); if (xlength(x) != n) return make_msg("Must have length %g, but has length %g", (double)n, (double)xlength(x)); } if (!isNull(min_len)) { R_xlen_t n = asCount(min_len, "min.len"); if (xlength(x) < n) return make_msg("Must have length >= %g, but has length %g", (double)n, (double)xlength(x)); } if (!isNull(max_len)) { R_xlen_t n = asCount(max_len, "max.len"); if (xlength(x) > n) return make_msg("Must have length <= %g, but has length %g", (double)n, (double)xlength(x)); } if (!asFlag(any_missing, "any.missing") && any_missing_atomic(x)) return make_msg("Contains missing values"); if (!asFlag(all_missing, "all.missing") && all_missing_atomic(x)) return make_msg("Contains only missing values"); if (asFlag(unique, "unique") && any_duplicated(x, FALSE) > 0) return make_msg("Contains duplicated values"); if (!isNull(names) && xlength(x) > 0) return check_names(getAttrib(x, R_NamesSymbol), names, "Vector"); return MSGT; } static msg_t check_matrix_props(SEXP x, SEXP any_missing, SEXP min_rows, SEXP min_cols, SEXP rows, SEXP cols) { if (!isNull(min_rows) || !isNull(rows)) { R_len_t xrows = get_nrows(x); if (!isNull(min_rows)) { R_len_t cmp = asCount(min_rows, "min.rows"); if (xrows < cmp) return make_msg("Must have at least %i rows, but has %i rows", cmp, xrows); } if (!isNull(rows)) { R_len_t cmp = asCount(rows, "rows"); if (xrows != cmp) return make_msg("Must have exactly %i rows, but has %i rows", cmp, xrows); } } if (!isNull(min_cols) || !isNull(cols)) { R_len_t xcols = get_ncols(x); if (!isNull(min_cols)) { R_len_t cmp = asCount(min_cols, "min.cols"); if (xcols < cmp) return make_msg("Must have at least %i cols, but has %i cols", cmp, xcols); } if (!isNull(cols)) { R_len_t cmp = asCount(cols, "cols"); if (xcols != cmp) return make_msg("Must have exactly %i cols, but has %i cols", cmp, xcols); } } if (!asFlag(any_missing, "any.missing") && any_missing_atomic(x)) return make_msg("Contains missing values"); return MSGT; } static msg_t check_storage(SEXP x, SEXP mode) { if (!isNull(mode)) { const char * const storage = asString(mode, "mode"); if (strcmp(storage, "logical") == 0) { if (!isLogical(x)) return make_msg("Must store logicals"); } else if (strcmp(storage, "integer") == 0) { if (!isInteger(x)) return make_msg("Must store integers"); } else if (strcmp(storage, "double") == 0) { if (!isReal(x)) return make_msg("Must store doubles"); } else if (strcmp(storage, "numeric") == 0) { if (!isStrictlyNumeric(x)) return make_msg("Must store numerics"); } else if (strcmp(storage, "complex") == 0) { if (!isComplex(x)) return make_msg("Must store complexs"); } else if (strcmp(storage, "character") == 0) { if (!isString(x)) return make_msg("Must store characters"); } else if (strcmp(storage, "list") == 0) { if (!isRList(x)) return make_msg("Must store a list"); } else if (strcmp(storage, "atomic") == 0) { if (!isVectorAtomic(x)) return make_msg("Must be atomic"); } else { error("Invalid argument 'mode'. Must be one of 'logical', 'integer', 'double', 'numeric', 'complex', 'character', 'list' or 'atomic'"); } } return MSGT; } /*********************************************************************************************************************/ /* Exported check functions */ /*********************************************************************************************************************/ SEXP c_check_character(SEXP x, SEXP min_chars, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isString(x) && !all_missing_atomic(x)) return make_type_error(x, "character"); if (!isNull(min_chars)) { R_xlen_t n = asCount(min_chars, "min.chars"); if (n > 0 && !all_nchar(x, n)) return make_result("All elements must have at least %g characters", (double)n); } return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_complex(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isComplex(x) && !all_missing_atomic(x)) return make_type_error(x, "complex"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_dataframe(SEXP x, SEXP any_missing, SEXP min_rows, SEXP min_cols, SEXP rows, SEXP cols, SEXP row_names, SEXP col_names) { if (!isFrame(x)) return make_type_error(x, "data.frame"); msg_t msg = check_matrix_props(x, any_missing, min_rows, min_cols, rows, cols); if (!msg.ok) return make_result(msg.msg); if (!isNull(row_names)) { SEXP nn = getAttrib(x, install("row.names")); if (isInteger(nn)) { nn = PROTECT(coerceVector(nn, STRSXP)); msg = check_names(nn, row_names, "Rows"); UNPROTECT(1); } else { msg = check_names(nn, row_names, "Rows"); } if (!msg.ok) return make_result(msg.msg); } if (!isNull(col_names)) { msg = check_names(getAttrib(x, R_NamesSymbol), col_names, "Columns"); if (!msg.ok) return make_result(msg.msg); } return ScalarLogical(TRUE); } SEXP c_check_factor(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isFactor(x) && !all_missing_atomic(x)) return make_type_error(x, "factor"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_integer(SEXP x, SEXP lower, SEXP upper, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isInteger(x) && !all_missing_atomic(x)) return make_type_error(x, "integer"); msg_t msg = check_bounds(x, lower, upper); if (!msg.ok) return make_result(msg.msg); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_integerish(SEXP x, SEXP tol, SEXP lower, SEXP upper, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isIntegerish(x, asTol(tol)) && !all_missing_atomic(x)) return make_type_error(x, "integerish"); msg_t msg = check_bounds(x, lower, upper); if (!msg.ok) return make_result(msg.msg); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_list(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isRList(x)) return make_type_error(x, "list"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_logical(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isLogical(x) && !all_missing_atomic(x)) return make_type_error(x, "logical"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_matrix(SEXP x, SEXP mode, SEXP any_missing, SEXP min_rows, SEXP min_cols, SEXP rows, SEXP cols, SEXP row_names, SEXP col_names) { if (!isMatrix(x)) return make_type_error(x, "matrix"); msg_t msg = check_storage(x, mode); if (!msg.ok) return make_result(msg.msg); msg = check_matrix_props(x, any_missing, min_rows, min_cols, rows, cols); if (!msg.ok) return make_result(msg.msg); if (!isNull(row_names) && xlength(x) > 0) { SEXP nn = getAttrib(x, R_DimNamesSymbol); if (!isNull(nn)) nn = VECTOR_ELT(nn, 0); msg = check_names(nn, row_names, "Rows"); if (!msg.ok) return make_result(msg.msg); } if (!isNull(col_names) && xlength(x) > 0) { SEXP nn = getAttrib(x, R_DimNamesSymbol); if (!isNull(nn)) nn = VECTOR_ELT(nn, 1); msg = check_names(nn, col_names, "Columns"); if (!msg.ok) return make_result(msg.msg); } return ScalarLogical(TRUE); } SEXP c_check_array(SEXP x, SEXP mode, SEXP any_missing, SEXP d, SEXP min_d, SEXP max_d) { if (!isArray(x)) return make_type_error(x, "array"); msg_t msg = check_storage(x, mode); if (!msg.ok) return make_result(msg.msg); if (!asFlag(any_missing, "any.missing") && any_missing_atomic(x)) return make_result("Contains missing values"); R_len_t ndim = length(getAttrib(x, R_DimSymbol)); if (!isNull(d)) { R_len_t di = asCount(d, "d"); if (ndim != di) return make_result("Must be a %i-d array, but has dimension %i", di, ndim); } if (!isNull(min_d)) { R_len_t di = asCount(min_d, "min.d"); if (ndim < di) return make_result("Must have >=%i dimensions, but has dimension %i", di, ndim); } if (!isNull(max_d)) { R_len_t di = asCount(max_d, "max.d"); if (ndim > di) return make_result("Must have <=%i dimensions, but has dimension %i", di, ndim); } return ScalarLogical(TRUE); } SEXP c_check_named(SEXP x, SEXP type) { if (!isNull(type) && xlength(x) > 0) return mwrap(check_names(getAttrib(x, R_NamesSymbol), type, "Object")); return ScalarLogical(TRUE); } SEXP c_check_names(SEXP x, SEXP type) { if (!isString(x)) return make_result("Must be a character vector of names"); return mwrap(check_names(x, type, "Object")); } SEXP c_check_numeric(SEXP x, SEXP lower, SEXP upper, SEXP finite, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isNumeric(x) && !all_missing_atomic(x)) return make_type_error(x, "numeric"); if (asFlag(finite, "finite") && any_infinite(x)) return make_result("Must be finite"); msg_t msg = check_bounds(x, lower, upper); if (!msg.ok) return make_result(msg.msg); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_vector(SEXP x, SEXP strict, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isVector(x) || ((asFlag(strict, "strict") && !is_vector(x)))) return make_type_error(x, "vector"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_atomic(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isNull(x) && !isVectorAtomic(x)) return make_type_error(x, "atomic"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } SEXP c_check_atomic_vector(SEXP x, SEXP any_missing, SEXP all_missing, SEXP len, SEXP min_len, SEXP max_len, SEXP unique, SEXP names) { if (!isVectorAtomic(x)) return make_type_error(x, "atomic vector"); return mwrap(check_vector_props(x, any_missing, all_missing, len, min_len, max_len, unique, names)); } /*********************************************************************************************************************/ /* Check functions for scalars */ /*********************************************************************************************************************/ SEXP c_check_flag(SEXP x, SEXP na_ok) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isLogical(x))) return make_type_error(x, "logical flag"); if (is_na && !asFlag(na_ok, "na.ok")) return make_result("May not be NA"); return ScalarLogical(TRUE); } SEXP c_check_count(SEXP x, SEXP na_ok, SEXP positive, SEXP tol) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isIntegerish(x, asTol(tol)))) return make_type_error(x, "count"); if (is_na) { if (!asFlag(na_ok, "na.ok")) return make_result("May not be NA"); } else { const int pos = (int) asFlag(positive, "positive"); if (asInteger(x) < pos) return make_result("Must be >= %i", pos); } return ScalarLogical(TRUE); } SEXP c_check_int(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP tol) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isIntegerish(x, asTol(tol)))) return make_type_error(x, "single integerish value"); if (is_na) { if (!asFlag(na_ok, "na.ok")) return make_result("May not be NA"); } return mwrap(check_bounds(x, lower, upper)); } SEXP c_check_number(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP finite) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isStrictlyNumeric(x))) return make_type_error(x, "number"); if (is_na) { if (!asFlag(na_ok, "na.ok")) return make_result("May not be NA"); return ScalarLogical(TRUE); } if (asFlag(finite, "finite") && any_infinite(x)) return make_result("Must be finite"); return mwrap(check_bounds(x, lower, upper)); } SEXP c_check_string(SEXP x, SEXP na_ok) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isString(x))) return make_type_error(x, "string"); if (is_na && !asFlag(na_ok, "na.ok")) return make_result("May not be NA"); return ScalarLogical(TRUE); } SEXP c_check_scalar(SEXP x, SEXP na_ok) { Rboolean is_na = is_scalar_na(x); if (xlength(x) != 1 || (!is_na && !isVectorAtomic(x))) return make_type_error(x, "atomic scalar"); if (is_na && !asFlag(na_ok, "na.ok")) return make_result("May not be NA"); return ScalarLogical(TRUE); } checkmate/src/any_missing.h0000644000175100001440000000105212540757715015507 0ustar hornikusers#ifndef CHECKMATE_ANY_MISSING_H_ #define CHECKMATE_ANY_MISSING_H_ #include #define USE_RINTERNALS #include Rboolean any_missing_logical(SEXP); Rboolean any_missing_integer(SEXP); Rboolean any_missing_integerish(SEXP); Rboolean any_missing_double(SEXP); Rboolean any_missing_numeric(SEXP); Rboolean any_missing_complex(SEXP); Rboolean any_missing_string(SEXP); Rboolean any_missing_atomic(SEXP); Rboolean any_missing_list(SEXP); Rboolean any_missing_matrix(SEXP); Rboolean any_missing_frame(SEXP); SEXP c_any_missing(SEXP); #endif checkmate/src/qassert.c0000644000175100001440000004121112540757715014645 0ustar hornikusers#include "qassert.h" #include "helper.h" #include "any_missing.h" #include "is_integerish.h" #include "cmessages.h" typedef enum { CL_LOGICAL, CL_INTEGER, CL_INTEGERISH, CL_NUMERIC, CL_DOUBLE, CL_STRING, CL_LIST, CL_COMPLEX, CL_ATOMIC, CL_ATOMIC_VECTOR, CL_MATRIX, CL_DATAFRAME, CL_ENVIRONMENT, CL_FUNCTION, CL_NULL, CL_NONE } class_t; typedef Rboolean(*dd_cmp)(double, double); typedef Rboolean(*ll_cmp)(R_xlen_t, R_xlen_t); typedef enum { LT, LE, EQ, GE, GT, NE, NONE } cmp_t; typedef struct { dd_cmp fun; double cmp; cmp_t op; } bound_t; typedef struct { struct { Rboolean(*fun)(SEXP); class_t name; } class; struct { Rboolean(*fun)(SEXP); } missing; struct { ll_cmp fun; R_xlen_t cmp; cmp_t op; } len; bound_t lower; bound_t upper; } checker_t; static inline Rboolean ii_eq(const R_xlen_t x, const R_xlen_t y) { return x == y; } static inline Rboolean ii_lt(const R_xlen_t x, const R_xlen_t y) { return x < y; } static inline Rboolean ii_gt(const R_xlen_t x, const R_xlen_t y) { return x > y; } static inline Rboolean ii_le(const R_xlen_t x, const R_xlen_t y) { return x <= y; } static inline Rboolean ii_ge(const R_xlen_t x, const R_xlen_t y) { return x >= y; } static inline Rboolean dd_lt(const double x, const double y) { return x < y; } static inline Rboolean dd_gt(const double x, const double y) { return x > y; } static inline Rboolean dd_le(const double x, const double y) { return x <= y; } static inline Rboolean dd_ge(const double x, const double y) { return x >= y; } static inline Rboolean dd_ne(const double x, const double y) { return x != y; } static inline Rboolean is_class_logical(SEXP x) { return isLogical(x); } static inline Rboolean is_class_integer(SEXP x) { return isInteger(x); } static inline Rboolean is_class_integerish(SEXP x) { return isIntegerish(x, INTEGERISH_DEFAULT_TOL); } static inline Rboolean is_class_double(SEXP x) { return isReal(x); } static inline Rboolean is_class_numeric(SEXP x) { return isStrictlyNumeric(x); } static inline Rboolean is_class_complex(SEXP x) { return isComplex(x); } static inline Rboolean is_class_string(SEXP x) { return isString(x); } static inline Rboolean is_class_atomic(SEXP x) { return isNull(x) || isVectorAtomic(x); } static inline Rboolean is_class_atomic_vector(SEXP x) { return isVectorAtomic(x); } static inline Rboolean is_class_list(SEXP x) { return isRList(x); } static inline Rboolean is_class_matrix(SEXP x) { return isMatrix(x); } static inline Rboolean is_class_frame(SEXP x) { return isFrame(x); } static inline Rboolean is_class_function(SEXP x) { return isFunction(x); } static inline Rboolean is_class_environment(SEXP x) { return isEnvironment(x); } static inline Rboolean is_class_null(SEXP x) { return isNull(x); } static const char * CMPSTR[] = { "<", "<=", "==", ">=", ">", "!=" }; static const char * CLSTR[] = { "logical", "integer", "integerish", "numeric", "double", "string", "list", "complex", "atomic", "atomic vector", "matrix", "data frame", "environment", "function", "NULL" }; /*********************************************************************************************************************/ /* Some helper functions */ /*********************************************************************************************************************/ static msg_t check_bound(SEXP x, const bound_t bound) { if (isReal(x)) { const double *xp = REAL(x); const double * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (!ISNAN(*xp) && !bound.fun(*xp, bound.cmp)) return make_msg("All elements must be %s %g", CMPSTR[bound.op], bound.cmp); } } else if (isInteger(x)) { const int *xp = INTEGER(x); const int * const xend = xp + xlength(x); for (; xp != xend; xp++) { if (*xp != NA_INTEGER && !bound.fun((double) *xp, bound.cmp)) return make_msg("All elements must be %s %g", CMPSTR[bound.op], bound.cmp); } } else { error("Bound checks only possible for numeric variables"); } return MSGT; } /*********************************************************************************************************************/ /* First step: Parse string and built checker_t object */ /*********************************************************************************************************************/ static int parse_class(checker_t *checker, const char *rule) { checker->missing.fun = NULL; switch(rule[0]) { case 'B': checker->missing.fun = &any_missing_logical; case 'b': checker->class.fun = &is_class_logical; checker->class.name = CL_LOGICAL; break; case 'I': checker->missing.fun = &any_missing_integer; case 'i': checker->class.fun = &is_class_integer; checker->class.name = CL_INTEGER; break; case 'X': checker->missing.fun = &any_missing_integerish; case 'x': checker->class.fun = &is_class_integerish; checker->class.name = CL_INTEGERISH; break; case 'N': checker->missing.fun = &any_missing_numeric; case 'n': checker->class.fun = &is_class_numeric; checker->class.name = CL_NUMERIC; break; case 'R': checker->missing.fun = &any_missing_double; case 'r': checker->class.fun = &is_class_double; checker->class.name = CL_DOUBLE; break; case 'S': checker->missing.fun = &any_missing_string; case 's': checker->class.fun = &is_class_string; checker->class.name = CL_STRING; break; case 'L': checker->missing.fun = &any_missing_list; case 'l': checker->class.fun = &is_class_list; checker->class.name = CL_LIST; break; case 'C': checker->missing.fun = &any_missing_complex; case 'c': checker->class.fun = &is_class_complex; checker->class.name = CL_COMPLEX; break; case 'A': checker->missing.fun = &any_missing_atomic; case 'a': checker->class.fun = &is_class_atomic; checker->class.name = CL_ATOMIC; break; case 'V': checker->missing.fun = &any_missing_atomic; case 'v': checker->class.fun = &is_class_atomic_vector; checker->class.name = CL_ATOMIC_VECTOR; break; case 'M': checker->missing.fun = &any_missing_matrix; case 'm': checker->class.fun = &is_class_matrix; checker->class.name = CL_MATRIX; break; case 'D': checker->missing.fun = &any_missing_frame; case 'd': checker->class.fun = &is_class_frame; checker->class.name = CL_DATAFRAME; break; case 'e': checker->class.fun = &is_class_environment; checker->class.name = CL_ENVIRONMENT; break; case 'f': checker->class.fun = &is_class_function; checker->class.name = CL_FUNCTION; break; case '0': checker->class.fun = &is_class_null; checker->class.name = CL_NULL; break; case '*': checker->class.fun = NULL; checker->class.name = CL_NONE; break; default: error("Unknown class identifier '%c'", rule[0]); } return 1; } static int parse_length(checker_t *checker, const char *rule) { switch(rule[0]) { case '*': checker->len.fun = NULL; return 1; case '?': checker->len.fun = &ii_le; checker->len.cmp = 1; checker->len.op = LE; return 1; case '+': checker->len.fun = &ii_ge; checker->len.cmp = 1; checker->len.op = GE; return 1; case '(': case '[': case '\0': checker->len.fun = NULL; checker->len.op = NONE; return 0; } const char *start = rule; switch(rule[0]) { case '=': checker->len.fun = &ii_eq; checker->len.op = EQ; start += 1 + (rule[1] == '='); break; case '<': if (rule[1] == '=') { checker->len.fun = &ii_le; checker->len.op = LE; start += 2; } else { checker->len.fun = &ii_lt; checker->len.op = LE; start += 1; } break; case '>': if (rule[1] == '=') { checker->len.fun = &ii_ge; checker->len.op = GE; start += 2; } else { checker->len.fun = &ii_gt; checker->len.op = GT; start += 1; } break; default: checker->len.fun = &ii_eq; checker->len.op = EQ; break; } char *end; long int cmp = strtol(start, &end, 10); if (start == end) error("Invalid length definition: %s", rule); if (cmp >= INT_MAX) error("Cannot handle length >= %i", INT_MAX); if (cmp < 0) error("Cannot check for negative length"); checker->len.cmp = (int)cmp; return end - rule; } static int parse_bounds(checker_t *checker, const char *rule) { switch(rule[0]) { case '\0': checker->lower.fun = NULL; checker->upper.fun = NULL; return 0; case '(': checker->lower.fun = &dd_gt; checker->lower.op = GT; break; case '[': checker->lower.fun = &dd_ge; checker->lower.op = GE; break; default: error("Invalid bound definition, missing opening '(' or '[': %s", rule); } char *end; const char *start = rule + 1; double cmp = strtod(start, &end); if (start == end) { if (checker->lower.op == GT) { checker->lower.fun = &dd_ne; checker->lower.cmp = R_NegInf; } else { checker->lower.fun = NULL; } } else { checker->lower.cmp = cmp; } switch(*end) { case ',' : start = end + 1; case ')' : case ']' : break; default : error("Invalid bound definition, error parsing lower bound, missing separator ',' or missing closing ')' or ']': %s", rule); } cmp = strtod(start, &end); if (*end == ')') { checker->upper.op = LT; if (start == end) { checker->upper.fun = &dd_ne; checker->upper.cmp = R_PosInf; } else { checker->upper.fun = &dd_lt; checker->upper.cmp = cmp; } } else if (*end == ']') { if (start == end) { checker->upper.fun = NULL; } else { checker->upper.fun = &dd_le; checker->upper.cmp = cmp; } } else { error("Invalid bound definition, error parsing upper bound or missing closing ')' or ']': %s", rule); } return end - rule + 1; } static void parse_rule(checker_t *checker, const char *rule) { const R_len_t nchars = strlen(rule); if (nchars == 0) error("Empty rule"); rule += parse_class(checker, rule); rule += parse_length(checker, rule); rule += parse_bounds(checker, rule); if (rule[0] == '\0') return; error("Additional chars found!"); } /*********************************************************************************************************************/ /* Second step: check SEXP using a checker_t object */ /*********************************************************************************************************************/ static msg_t check_rule(SEXP x, const checker_t *checker, const Rboolean err_msg) { if (checker->class.fun != NULL && !checker->class.fun(x)) { return err_msg ? make_msg("Must be of class '%s', not '%s'", CLSTR[checker->class.name], guessType(x)) : MSGF; } if (checker->missing.fun != NULL && checker->missing.fun(x)) { return err_msg ? make_msg("May not contain missing values") : MSGF; } if (checker->len.fun != NULL && !checker->len.fun(xlength(x), checker->len.cmp)) { return err_msg ? make_msg("Must be of length %s %i, but has length %g", CMPSTR[checker->len.op], checker->len.cmp, (double)xlength(x)) : MSGF; } if (checker->lower.fun != NULL) { msg_t msg = check_bound(x, checker->lower); if (!msg.ok) return msg; } if (checker->upper.fun != NULL) { msg_t msg = check_bound(x, checker->upper); if (!msg.ok) return msg; } return MSGT; } /*********************************************************************************************************************/ /* qassert stuff */ /*********************************************************************************************************************/ static inline R_len_t qassert1(SEXP x, const checker_t *checker, msg_t *result, const R_len_t nrules) { for (R_len_t i = 0; i < nrules; i++) { result[i] = check_rule(x, &checker[i], result[i].ok); if (result[i].ok) return 0; } return 1; } static inline R_len_t qassert_list(SEXP x, const checker_t *checker, msg_t *result, const R_len_t nrules) { if (!isNewList(x) || isNull(x)) error("Argument 'x' must be a list or data.frame"); const R_len_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (qassert1(VECTOR_ELT(x, i), checker, result, nrules) != 0) return i + 1; } return 0; } SEXP c_qassert(SEXP x, SEXP rules, SEXP recursive) { const Rboolean nrules = length(rules); R_len_t failed; if (!isString(rules)) error("Argument 'rules' must be a string"); if (nrules == 0) return ScalarLogical(TRUE); msg_t result[nrules]; checker_t checker[nrules]; SEXP tmp; for (R_len_t i = 0; i < nrules; i++) { tmp = STRING_ELT(rules, i); if (tmp == NA_STRING) error("Rule may not be NA"); parse_rule(&checker[i], CHAR(tmp)); result[i].ok = TRUE; } if (LOGICAL(recursive)[0]) { failed = qassert_list(x, checker, result, nrules); } else { failed = qassert1(x, checker, result, nrules); } if (failed == 0) return ScalarLogical(TRUE); SEXP msgs = PROTECT(allocVector(STRSXP, nrules)); SEXP pos = PROTECT(ScalarInteger(failed)); setAttrib(msgs, install("pos"), pos); for (R_len_t i = 0; i < nrules; i++) SET_STRING_ELT(msgs, i, mkChar(result[i].msg)); UNPROTECT(2); return msgs; } /*********************************************************************************************************************/ /* qtest stuff */ /*********************************************************************************************************************/ static inline Rboolean qtest1(SEXP x, const checker_t *checker, const R_len_t nrules) { msg_t result; for (R_len_t i = 0; i < nrules; i++) { result = check_rule(x, &checker[i], FALSE); if (result.ok) return TRUE; } return FALSE; } static inline Rboolean qtest_list(SEXP x, const checker_t *checker, const R_len_t nrules) { if (!isNewList(x)) error("Argument 'x' must be a list or data.frame"); const R_len_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (!qtest1(VECTOR_ELT(x, i), checker, nrules)) return FALSE; } return TRUE; } SEXP c_qtest(SEXP x, SEXP rules, SEXP recursive) { const R_len_t nrules = length(rules); if (!isString(rules)) error("Argument 'rules' must be a string"); if (nrules == 0) return ScalarLogical(TRUE); checker_t checker[nrules]; SEXP tmp; for (R_len_t i = 0; i < nrules; i++) { tmp = STRING_ELT(rules, i); if (tmp == NA_STRING) error("Rule may not be NA"); parse_rule(&checker[i], CHAR(STRING_ELT(rules, i))); } return LOGICAL(recursive)[0] ? ScalarLogical(qtest_list(x, checker, nrules)) : ScalarLogical(qtest1(x, checker, nrules)); } checkmate/src/is_integerish.c0000644000175100001440000000227512540757715016026 0ustar hornikusers#include "is_integerish.h" #include #include static inline Rboolean is_unconvertible(const double x, const double tol) { return (!ISNAN(x) && (x <= INT_MIN || x > INT_MAX || fabs(x - nearbyint(x)) >= tol)); } static inline Rboolean is_integerish_double(SEXP x, const double tol) { const double *xr = REAL(x); const double * const xend = xr + length(x); for (; xr != xend; xr++) { if (is_unconvertible(*xr, tol)) return FALSE; } return TRUE; } static inline Rboolean is_integerish_complex(SEXP x, const double tol) { const Rcomplex * xc = COMPLEX(x); const Rcomplex * const xe = xc + length(x); for (; xc != xe; xc++) { if (fabs((*xc).i) >= tol || is_unconvertible((*xc).r, tol)) return FALSE; } return TRUE; } Rboolean isIntegerish(SEXP x, double tol) { switch(TYPEOF(x)) { case LGLSXP: return TRUE; case INTSXP: return TRUE; case REALSXP: return is_integerish_double(x, tol); case CPLXSXP: return is_integerish_complex(x, tol); } return FALSE; } SEXP c_is_integerish(SEXP x, SEXP tolerance) { return ScalarLogical(isIntegerish(x, REAL(tolerance)[0])); } checkmate/src/all_missing.c0000644000175100001440000000503212540757715015465 0ustar hornikusers#include "all_missing.h" Rboolean all_missing_logical(SEXP x) { const int * xp = LOGICAL(x); const int * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (*xp != NA_LOGICAL) return FALSE; } return TRUE; } Rboolean all_missing_integer(SEXP x) { const int * xp = INTEGER(x); const int * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (*xp != NA_INTEGER) return FALSE; } return TRUE; } Rboolean all_missing_double(SEXP x) { const double * xp = REAL(x); const double * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (!ISNAN(*xp)) return FALSE; } return TRUE; } Rboolean all_missing_complex(SEXP x) { const Rcomplex * xp = COMPLEX(x); const Rcomplex * const xe = xp + xlength(x); for (; xp != xe; xp++) { if (!ISNAN((*xp).r) || !ISNAN((*xp).i)) return FALSE; } return TRUE; } Rboolean all_missing_string(SEXP x) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (STRING_ELT(x, i) != NA_STRING) return FALSE; } return TRUE; } Rboolean all_missing_atomic(SEXP x) { switch(TYPEOF(x)) { case LGLSXP: return all_missing_logical(x); case INTSXP: return all_missing_integer(x); case REALSXP: return all_missing_double(x); case CPLXSXP: return all_missing_complex(x); case STRSXP: return all_missing_string(x); default: return FALSE; } } Rboolean all_missing_list(SEXP x) { const R_xlen_t nx = xlength(x); for (R_xlen_t i = 0; i < nx; i++) { if (!isNull(VECTOR_ELT(x, i))) return FALSE; } return TRUE; } Rboolean all_missing_frame(SEXP x) { const R_xlen_t nc = xlength(x); for (R_xlen_t i = 0; i < nc; i++) { if (!all_missing_atomic(VECTOR_ELT(x, i))) return FALSE; } return TRUE; } Rboolean all_missing(SEXP x) { switch(TYPEOF(x)) { case LGLSXP: return all_missing_logical(x); case INTSXP: return all_missing_integer(x); case REALSXP: return all_missing_double(x); case CPLXSXP: return all_missing_complex(x); case STRSXP: return all_missing_string(x); case NILSXP: return FALSE; case VECSXP: return isFrame(x) ? all_missing_frame(x) : all_missing_list(x); case RAWSXP: return FALSE; default: error("Object of type '%s' not supported", type2char(TYPEOF(x))); } } SEXP c_all_missing(SEXP x) { return ScalarLogical(all_missing(x)); } checkmate/src/checks.h0000644000175100001440000000272712540757715014441 0ustar hornikusers#ifndef CHECKMATE_CHECKS_H_ #define CHECKMATE_CHECKS_H_ #include #define USE_RINTERNALS #include #include "cmessages.h" SEXP c_check_character(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_complex(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_dataframe(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_factor(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_integer(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_integerish(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_list(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_logical(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_matrix(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_array(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_named(SEXP, SEXP); SEXP c_check_names(SEXP, SEXP); SEXP c_check_numeric(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_vector(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_atomic(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_atomic_vector(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_flag(SEXP, SEXP); SEXP c_check_count(SEXP, SEXP, SEXP, SEXP); SEXP c_check_int(SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_number(SEXP, SEXP, SEXP, SEXP, SEXP); SEXP c_check_string(SEXP, SEXP); SEXP c_check_scalar(SEXP, SEXP); #endif checkmate/src/qassert.h0000644000175100001440000000030412540757715014650 0ustar hornikusers#ifndef CHECKMATE_QASSERT_H_ #define CHECKMATE_QASSERT_H_ #include #define USE_RINTERNALS #include SEXP c_qassert(SEXP, SEXP, SEXP); SEXP c_qtest(SEXP, SEXP, SEXP); #endif checkmate/NAMESPACE0000644000175100001440000000643112524117441013440 0ustar hornikusers# Generated by roxygen2 (4.1.1): do not edit by hand export(allMissing) export(anyInfinite) export(anyMissing) export(asCount) export(asInt) export(asInteger) export(assert) export(assertAccess) export(assertArray) export(assertAtomic) export(assertAtomicVector) export(assertCharacter) export(assertChoice) export(assertClass) export(assertComplex) export(assertCount) export(assertDataFrame) export(assertDirectory) export(assertEnvironment) export(assertFactor) export(assertFile) export(assertFlag) export(assertFunction) export(assertInt) export(assertInteger) export(assertIntegerish) export(assertList) export(assertLogical) export(assertMatrix) export(assertNamed) export(assertNames) export(assertNull) export(assertNumber) export(assertNumeric) export(assertPathForOutput) export(assertPercentage) export(assertScalar) export(assertScalarNA) export(assertSetEqual) export(assertString) export(assertSubset) export(assertVector) export(checkAccess) export(checkArray) export(checkAtomic) export(checkAtomicVector) export(checkCharacter) export(checkChoice) export(checkClass) export(checkComplex) export(checkCount) export(checkDataFrame) export(checkDirectory) export(checkEnvironment) export(checkFactor) export(checkFile) export(checkFlag) export(checkFunction) export(checkInt) export(checkInteger) export(checkIntegerish) export(checkList) export(checkLogical) export(checkMatrix) export(checkNamed) export(checkNames) export(checkNull) export(checkNumber) export(checkNumeric) export(checkPathForOutput) export(checkPercentage) export(checkScalar) export(checkScalarNA) export(checkSetEqual) export(checkString) export(checkSubset) export(checkVector) export(qassert) export(qassertr) export(qtest) export(qtestr) export(testAccess) export(testArray) export(testAtomic) export(testAtomicVector) export(testCharacter) export(testChoice) export(testClass) export(testComplex) export(testCount) export(testDataFrame) export(testDirectory) export(testEnvironment) export(testFactor) export(testFile) export(testFlag) export(testFunction) export(testInt) export(testInteger) export(testIntegerish) export(testList) export(testLogical) export(testMatrix) export(testNamed) export(testNames) export(testNull) export(testNumber) export(testNumeric) export(testPathForOutput) export(testPercentage) export(testScalar) export(testScalarNA) export(testSetEqual) export(testString) export(testSubset) export(testVector) useDynLib(checkmate,c_all_missing) useDynLib(checkmate,c_any_infinite) useDynLib(checkmate,c_any_missing) useDynLib(checkmate,c_check_array) useDynLib(checkmate,c_check_atomic) useDynLib(checkmate,c_check_atomic_vector) useDynLib(checkmate,c_check_character) useDynLib(checkmate,c_check_complex) useDynLib(checkmate,c_check_count) useDynLib(checkmate,c_check_dataframe) useDynLib(checkmate,c_check_factor) useDynLib(checkmate,c_check_flag) useDynLib(checkmate,c_check_int) useDynLib(checkmate,c_check_integer) useDynLib(checkmate,c_check_list) useDynLib(checkmate,c_check_logical) useDynLib(checkmate,c_check_matrix) useDynLib(checkmate,c_check_named) useDynLib(checkmate,c_check_names) useDynLib(checkmate,c_check_number) useDynLib(checkmate,c_check_numeric) useDynLib(checkmate,c_check_string) useDynLib(checkmate,c_check_vector) useDynLib(checkmate,c_is_integerish) useDynLib(checkmate,c_qassert) useDynLib(checkmate,c_qtest) checkmate/NEWS0000644000175100001440000000600012540757610012716 0ustar hornikusersVersion 1.6.0 (2015-06-19) ------------------------------------------------------------------------------- * Started to support long vectors * Added a short vignette * Improved documentation * New argument "combine" for assert() to allow combining check functions with an AND instead of an OR Version 1.5.3 (2015-05-13) ------------------------------------------------------------------------------- * Fixed a bug regarding the number of rows in zero-column data frames. * Fixed a bug where the type of lists with dimension attribute where reported as "array" or "matrix" * Family *Array: new arguments "min.d" and "max.d" * Family *Array and *Matrix: Argument "mode" now additionally accepts strings "list" and "atomic" Version 1.5.2 (2015-03-19) ------------------------------------------------------------------------------- * Fixed: (assert|check|test)Character(NA_character_, min.chars = 1) does not eval to TRUE anymore. * New arguments for *Factor functions: (n|min|max).levels. * Improved error messages for type and length checks * Improved error messages for missing arguments Version 1.5.1 (2014-12-13) ------------------------------------------------------------------------------- * Included a workaround for R's nrow and ncol to properly worh with data frames * Fixed a bug handling complex number in checks for integerish values * Improved documentation Version 1.5.0 (2014-10-18) ------------------------------------------------------------------------------- * Added checkNames * Added checkPercentage * Added anyInfinite * Fixed error messages for some dimension checks * Fixed an error while checking numerics for finiteness Version 1.4 (2014-09-03) ------------------------------------------------------------------------------- * Fixed a bug where rownames and colnames of data.frames where not retrieved correctly * Fixed a bug in checkVector (wrong order of arguments in call to C) * Filesystem access: checks for write and executable rights are now disabled on windows Version 1.3 (2014-08-15) ------------------------------------------------------------------------------- * Fixed a bug where logical values passed a check for numerics in "qassert" * Family *SetEqual: new argument "ordered" * checkPathForOutput: new argument "overwrite" Version 1.2 (2014-07-21) ------------------------------------------------------------------------------- * Fixed bug in checkList * Fixed dimnames check on empty matrices and data frames * Added *SetEqual functions Version 1.1 (2014-06-28) ------------------------------------------------------------------------------- * Improved error messages in assert* functions * New argument 'empty.ok' for *Subset functions * assert() now returns TRUE invisibly (as documented) * Fixed handling of zero-length arguments in checkFunction * Fixed error message if duplicated values where found * Fixed a missing check for row names in checkMatrix and checkDataFrame Version 1.0 (2014-06-17) ------------------------------------------------------------------------------- * Initial release on CRAN checkmate/R/0000755000175100001440000000000012540747441012425 5ustar hornikuserscheckmate/R/checkCharacter.r0000644000175100001440000000534112514153643015501 0ustar hornikusers#' Check if an argument is a vector of type character #' #' @templateVar fn Character #' @template x #' @template na-handling #' @inheritParams checkVector #' @param pattern [\code{character(1L)}]\cr #' Regular expression as used in \code{\link[base]{grepl}}. #' All elements of \code{x} must comply to this pattern. #' Defaults to \code{NULL}. #' @param ignore.case [\code{logical(1)}]\cr #' See \code{\link[base]{grepl}}. Default is \code{FALSE}. #' @param fixed [\code{logical(1)}]\cr #' See \code{\link[base]{grepl}}. Default is \code{FALSE}. #' @param min.chars [\code{integer(1)}]\cr #' Minimum number of characters in each element of \code{x}. #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_character #' @export #' @examples #' testCharacter(letters, min.len = 1, any.missing = FALSE) #' testCharacter(letters, min.chars = 2) #' testCharacter("example", pattern = "xa") checkCharacter = function(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_character", x, min.chars, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") %and% checkCharacterProps(x, pattern, fixed, ignore.case) } #' @rdname checkCharacter #' @useDynLib checkmate c_check_character #' @export assertCharacter = function(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_character", x, min.chars, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) res = checkCharacterProps(x, pattern, fixed, ignore.case) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkCharacter #' @useDynLib checkmate c_check_character #' @export testCharacter = function(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_character", x, min.chars, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) && isTRUE(checkCharacterProps(x, pattern, fixed, ignore.case)) } checkCharacterProps = function(x, pattern = NULL, fixed = FALSE, ignore.case = FALSE) { if (!is.null(pattern)) { qassert(pattern, "S1") qassert(fixed, "B1") qassert(ignore.case, "B1") ok = grepl(pattern, x, fixed = fixed, ignore.case = ignore.case) if(!all(ok)) return(sprintf("Must comply to pattern '%s", pattern)) } return(TRUE) } checkmate/R/checkNamed.r0000644000175100001440000000250512536530151014625 0ustar hornikusers#' Check if an argument is named #' #' @templateVar fn Named #' @template x #' @param type [character(1)]\cr #' Select the check(s) to perform. #' \dQuote{unnamed} checks \code{x} to be unnamed. #' \dQuote{named} (default) checks \code{x} to be named which excludes names to be \code{NA} or emtpy (\code{""}). #' \dQuote{unique} additionally tests for non-duplicated names. #' \dQuote{strict} checks for unique names which comply to R's variable name restrictions. #' Note that for zero-length \code{x} every name check evalutes to \code{TRUE}. #' Also note that you can use \code{\link{checkSubset}} to check for a specific set of names. #' @template checker #' @useDynLib checkmate c_check_named #' @export #' @examples #' x = 1:3 #' testNamed(x, "unnamed") #' names(x) = letters[1:3] #' testNamed(x, "unique") checkNamed = function(x, type = "named") { .Call("c_check_named", x, type, PACKAGE = "checkmate") } #' @rdname checkNamed #' @useDynLib checkmate c_check_named #' @export assertNamed = function(x, type = "named", .var.name) { res = .Call("c_check_named", x, type, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkNamed #' @useDynLib checkmate c_check_named #' @export testNamed = function(x, type = "named") { res = .Call("c_check_named", x, type, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkSubset.r0000644000175100001440000000206312536530075015052 0ustar hornikusers#' Check if object is a subset of a given set #' #' @templateVar fn Subset #' @template x #' @param choices [\code{atomic}]\cr #' Set of possible values. #' @param empty.ok [\code{logical(1)}]\cr #' Treat zero-length \code{x} as subset of any set \code{choices}? #' Default is \code{TRUE}. #' @template checker #' @family set #' @export #' @examples #' testSubset(c("a", "z"), letters) #' testSubset("ab", letters) #' testSubset("Species", names(iris)) checkSubset = function(x, choices, empty.ok = TRUE) { qassert(choices, "a+") qassert(empty.ok, "B1") if (!empty.ok && length(x) == 0L) return("Empty set not allowed") if (any(x %nin% choices)) return(sprintf("Must be a subset of {'%s'}", collapse(choices, "','"))) return(TRUE) } #' @rdname checkSubset #' @export assertSubset = function(x, choices, empty.ok = TRUE, .var.name) { res = checkSubset(x, choices, empty.ok) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkSubset #' @export testSubset = function(x, choices, empty.ok = TRUE) { isTRUE(checkSubset(x, choices, empty.ok)) } checkmate/R/allMissing.r0000644000175100001440000000035012524615454014710 0ustar hornikusers#' @rdname anyMissing #' @useDynLib checkmate c_all_missing #' @export #' @examples #' allMissing(1:2) #' allMissing(c(1, NA)) #' allMissing(c(NA, NA)) allMissing = function(x) { .Call("c_all_missing", x, PACKAGE = "checkmate") } checkmate/R/checkScalar.r0000644000175100001440000000141012514153643015003 0ustar hornikusers#' Check if an argument is a single atomic value #' #' @templateVar fn Scalar #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template checker #' @family scalars #' @export #' @examples #' testScalar(1) #' testScalar(1:10) checkScalar = function(x, na.ok = FALSE) { .Call("c_check_scalar", x, na.ok, PACKAGE = "checkmate") } #' @rdname checkScalar #' @export assertScalar = function(x, na.ok = FALSE, .var.name) { res = .Call("c_check_scalar", x, na.ok, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkScalar #' @export testScalar = function(x, na.ok = FALSE) { res = .Call("c_check_scalar", x, na.ok, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkNames.r0000644000175100001440000000267512536530167014663 0ustar hornikusers#' Check names to comply to specific rules #' #' @description #' Similar to \code{\link{checkNamed}} but you can pass the names directly. #' #' @templateVar fn Named #' @param x [\code{character} || \code{NULL}]\cr #' Names to check using rules defined via \code{type}. #' @param type [character(1)]\cr #' Select the check(s) to perform. #' \dQuote{unnamed} checks \code{x} to be \code{NULL}. #' \dQuote{named} (default) checks \code{x} for reguluar names which excludes names to be \code{NA} or emtpy (\code{""}). #' \dQuote{unique} additionally tests for non-duplicated names. #' \dQuote{strict} checks for unique names which comply to R's variable name restrictions. #' Note that you can use \code{\link{checkSubset}} to check for a specific set of names. #' @template checker #' @useDynLib checkmate c_check_named #' @export #' @examples #' x = 1:3 #' testNames(x, "unnamed") #' names(x) = letters[1:3] #' testNames(x, "unique") checkNames = function(x, type = "named") { .Call("c_check_names", x, type, PACKAGE = "checkmate") } #' @rdname checkNames #' @useDynLib checkmate c_check_names #' @export assertNames = function(x, type = "named", .var.name) { res = .Call("c_check_names", x, type, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkNames #' @useDynLib checkmate c_check_names #' @export testNames = function(x, type = "named") { res = .Call("c_check_names", x, type, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkList.r0000644000175100001440000000620212514153643014515 0ustar hornikusers#' Check if an argument is a list #' #' @templateVar fn List #' @template x #' @inheritParams checkVector #' @param ... [ANY]\cr #' Additional parameters used in a call of \code{\link{checkVector}}. #' @param types [\code{character}]\cr #' Character vector of class names. Each list element must inherit #' from at least one of the provided types. #' The types \dQuote{logical}, \dQuote{integer}, \dQuote{integerish}, \dQuote{double}, #' \dQuote{numeric}, \dQuote{complex}, \dQuote{character}, \dQuote{factor}, \dQuote{atomic}, \dQuote{vector} #' \dQuote{atomicvector}, \dQuote{array}, \dQuote{matrix}, \dQuote{list}, \dQuote{function}, #' \dQuote{environment} and \dQuote{null} are supported. #' For other types \code{\link[base]{inherits}} is used as a fallback to check \code{x}'s inheritance. #' Defaults to \code{character(0)} (no check). #' @template checker #' @family basetypes #' @export #' @useDynLib checkmate c_check_list #' @examples #' testList(list()) #' testList(as.list(iris), types = c("numeric", "factor")) checkList = function(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_list", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") %and% checkListProps(x, types) } #' @rdname checkList #' @useDynLib checkmate c_check_list #' @export assertList = function(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_list", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) res = checkListProps(x, types) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkList #' @useDynLib checkmate c_check_list #' @export testList = function(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_list", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) && isTRUE(checkListProps(x, types)) } checkListProps = function(x, types = character(0L)) { if (length(types) == 0L) return(TRUE) qassert(types, "S") ind = seq_along(x) for (type in types) { f = switch(type, "logical" = is.logical, "integer" = is.integer, "integerish" = isIntegerish, "double" = is.double, "numeric" = is.numeric, "complex" = is.complex, "character" = is.character, "factor" = is.factor, "atomic" = is.atomic, "vector" = is.vector, "atomicvector" = function(x) !is.null(x) && is.atomic(x), "array" = is.array, "matrix" = is.matrix, "function" = is.function, "environment" = is.environment, "list" = is.list, "null" = is.null, function(x) inherits(x, type) ) ind = ind[!vapply(x[ind], f, FUN.VALUE = NA, USE.NAMES = FALSE)] if (length(ind) == 0L) return(TRUE) } return(sprintf("May only contain the following types: %s", collapse(types))) } checkmate/R/qassert.r0000644000175100001440000001101512536546056014274 0ustar hornikusers#' Quick argument checks on (builtin) R types #' #' @description #' The provided functions parse rules which allow to express some of the most #' frequent argument checks by typing just a few letters. #' #' @param x [any]\cr #' Object the check. #' @param rules [\code{character}]\cr #' Set of rules. See details. #' @param .var.name [\code{logical(1)}]\cr #' Argument name to print in error message. If missing, #' the name of \code{x} will be retrieved via \code{\link[base]{substitute}}. #' @return [logical(1)]: \code{TRUE} on success, \code{FALSE} (or a thrown exception) otherwise. #' #' @details #' \code{qassert} throws an \code{R} exception if object \code{x} does #' not comply to at least one of the \code{rules} and returns \code{TRUE} #' otherwise. #' \code{qtest} behaves the same way but returns \code{FALSE} if none of the #' \code{rules} comply. #' #' The rule is specified in up to three parts. #' \enumerate{ #' \item{ #' Class and missingness check. #' The first letter is an abbreviation for the class. If it is #' provided uppercase, missing values are prohibited. #' Supported abbreviations: #' \tabular{rl}{ #' \code{[bB]} \tab Bool / logical.\cr #' \code{[iI]} \tab Integer.\cr #' \code{[xX]} \tab Integerish (numeric convertible to integer, see \code{\link{checkIntegerish}}).\cr #' \code{[rR]} \tab Real / double.\cr #' \code{[cC]} \tab Complex.\cr #' \code{[nN]} \tab Numeric (integer or double).\cr #' \code{[sS]} \tab String / character.\cr #' \code{[aA]} \tab Atomic.\cr #' \code{[vV]} \tab Atomic vector (see \code{\link{checkAtomicVector}}).\cr #' \code{[lL]} \tab List. Missingness is defined as \code{NULL} element.\cr #' \code{[mM]} \tab Matrix.\cr #' \code{[dD]} \tab Data.frame. Missingness is checked recursively on columns.\cr #' \code{[e]} \tab Environment.\cr #' \code{[f]} \tab Function.\cr #' \code{[0]} \tab \code{NULL}.\cr #' \code{[*]} \tab placeholder to allow any type. #' } #' Note that the check for missingness does not distinguish between #' \code{NaN} and \code{NA}. Infinite values are not treated as missing, but #' can be catched using boundary checks (part 3). #' } #' \item{ #' Length definition. This can be one of #' \tabular{rl}{ #' \code{[*]} \tab any length,\cr #' \code{[?]} \tab length of zero or one,\cr #' \code{[+]} \tab length of at least one, or\cr #' \code{[0-9]+} \tab exact length specified as integer. #' } #' Preceding the exact length with one of the comparison operators \code{=}/\code{==}, #' \code{<}, \code{<=}, \code{>=} or \code{>} is also supported. #' } #' \item{ #' Range check as two numbers separated by a comma, enclosed by square brackets #' (endpoint included) or parentheses (endpoint excluded). #' For example, \dQuote{[0, 3)} would trigger the check \code{all(x >= 0 & x < 3)}. #' Endpoints may be omitted which is the equivalent of an infinite endpoint. #' By definition \code{[0,]} contains \code{Inf}, while \code{[0,)} does not. #' The same holds for the left (lower) endpoint and \code{-Inf}. #' E.g., the rule \dQuote{N1()} checks for a single finite numeric which is not NA, #' while \dQuote{N1[)} would allow \code{-Inf}. #' } #' } #' @note #' The functions are inspired by the blog post of Bogumił Kamiński: #' \url{http://rsnippets.blogspot.de/2013/06/testing-function-agruments-in-gnu-r.html}. #' The implementation is mostly written in C to minimize the overhead. #' @seealso \code{\link{qtestr}} and \code{\link{qassertr}} for efficient checks #' of list elements and data frame columns. #' @useDynLib checkmate c_qassert #' @export #' @examples #' # logical of length 1 #' qtest(NA, "b1") #' #' # logical of length 1, NA not allowed #' qtest(NA, "B1") #' #' # logical of length 0 or 1, NA not allowed #' qtest(TRUE, "B?") #' #' # numeric with length > 0 #' qtest(runif(10), "n+") #' #' # integer with length > 0, NAs not allowed, all integers >= 0 and < Inf #' qtest(1:3, "I+[0,)") #' #' # either an emtpy list or a character vector with <=5 elements #' qtest(1, c("l0", "s<=5")) #' #' # data frame with at least one column and no missing value in any column #' qtest(iris, "D+") qassert = function(x, rules, .var.name) { res = .Call("c_qassert", x, rules, FALSE, PACKAGE = "checkmate") if (!isTRUE(res)) mstop(qamsg(x, res, vname(x, .var.name))) invisible(TRUE) } #' @useDynLib checkmate c_qtest #' @rdname qassert #' @export qtest = function(x, rules) { .Call("c_qtest", x, rules, FALSE, PACKAGE = "checkmate") } checkmate/R/checkFunction.r0000644000175100001440000000327712514153643015400 0ustar hornikusers#' Check if an argument is a function #' #' @templateVar fn Function #' @template x #' @param args [\code{character}]\cr #' Expected formal arguments. Checks that a function has no arguments if #' set to \code{character(0)}. #' Default is \code{NULL} (no check). #' @param ordered [\code{logical(1)}]\cr #' Flag whether the arguments provided in \code{args} must be the first #' \code{length(args)} arguments of the function in the specified order. #' Default is \code{FALSE}. #' @template checker #' @family basetypes #' @export #' @examples #' testFunction(mean) #' testFunction(mean, args = "x") checkFunction = function(x, args = NULL, ordered = FALSE) { qassert(ordered, "B1") x = try(match.fun(x), silent = TRUE) if (inherits(x, "try-error")) return("Function not found") if (!is.null(args)) { qassert(args, "S") fargs = names(formals(x)) if (is.null(fargs)) fargs = character(0L) if (length(args) == 0L) { if (length(fargs) > 0L) return("May not have any arguments") return(TRUE) } if (ordered) { if (any(args != head(fargs, length(args)))) { return(sprintf("Must have first formal arguments (ordered): %s", collapse(args))) } } else { tmp = setdiff(args, fargs) if (length(tmp)) return(sprintf("Must have formal arguments: %s", collapse(tmp))) } } return(TRUE) } #' @rdname checkFunction #' @export assertFunction = function(x, args = NULL, ordered = FALSE, .var.name) { res = checkFunction(x, args, ordered) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkFunction #' @export testFunction = function(x, args = NULL, ordered = FALSE) { isTRUE(checkFunction(x, args, ordered)) } checkmate/R/checkMatrix.r0000644000175100001440000000436212536527770015065 0ustar hornikusers#' Check if an argument is a matrix #' #' @templateVar fn Matrix #' @template x #' @template mode #' @param any.missing [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{TRUE}. #' @param min.rows [\code{integer(1)}]\cr #' Minimum number of rows. #' @param min.cols [\code{integer(1)}]\cr #' Minimum number of columns. #' @param nrows [\code{integer(1)}]\cr #' Exact number of rows. #' @param ncols [\code{integer(1)}]\cr #' Exact number of columns. #' @param row.names [\code{character(1)}]\cr #' Check for row names. Default is \dQuote{NULL} (no check). #' See \code{\link{checkNamed}} for possible values. #' Note that you can use \code{\link{checkSubset}} to check for a specific set of names. #' @param col.names [\code{character(1)}]\cr #' Check for column names. Default is \dQuote{NULL} (no check). #' See \code{\link{checkNamed}} for possible values. #' Note that you can use \code{\link{checkSubset}} to test for a specific set of names. #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_matrix #' @export #' @examples #' x = matrix(1:9, 3) #' colnames(x) = letters[1:3] #' testMatrix(x, nrows = 3, min.cols = 1, col.names = "named") checkMatrix = function(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) { .Call("c_check_matrix", x, mode, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") } #' @rdname checkMatrix #' @useDynLib checkmate c_check_matrix #' @export assertMatrix = function(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, .var.name) { res = .Call("c_check_matrix", x, mode, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkMatrix #' @useDynLib checkmate c_check_matrix #' @export testMatrix = function(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) { res = .Call("c_check_matrix", x, mode, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkNumeric.r0000644000175100001440000000316312514153643015207 0ustar hornikusers#' Check that an argument is a vector of type numeric #' #' @templateVar fn Numeric #' @template x #' @template na-handling #' @inheritParams checkVector #' @template bounds #' @param finite [\code{logical(1)}]\cr #' Check for only finite values? Default is \code{FALSE}. #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_numeric #' @export #' @examples #' testNumeric(1) #' testNumeric(1, min.len = 1, lower = 0) checkNumeric = function(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_numeric", x, lower, upper, finite, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkNumeric #' @useDynLib checkmate c_check_numeric #' @export assertNumeric = function(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_numeric", x, lower, upper, finite, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkNumeric #' @useDynLib checkmate c_check_numeric #' @export testNumeric = function(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_numeric", x, lower, upper, finite, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkNull.r0000644000175100001440000000070212514153643014513 0ustar hornikusers#' Check if an argument is NULL #' #' @templateVar fn Null #' @template x #' @template checker #' @export #' @examples #' testNull(NULL) #' testNull(1) checkNull = function(x) { if (!is.null(x)) return("Must be NULL") return(TRUE) } #' @rdname checkNull #' @export assertNull = function(x, .var.name) { res = checkNull(x) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkNull #' @export testNull = function(x) { is.null(x) } checkmate/R/checkInt.r0000644000175100001440000000205212514153643014333 0ustar hornikusers#' Check if an argument is a single integerish value #' #' @templateVar fn Int #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template bounds #' @template tol #' @template checker #' @family scalars #' @useDynLib checkmate c_check_int #' @export #' @examples #' testInt(1) #' testInt(-1, lower = 0) checkInt = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps)) { .Call("c_check_int", x, na.ok, lower, upper, tol, PACKAGE = "checkmate") } #' @rdname checkInt #' @export assertInt = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name) { res = .Call("c_check_int", x, na.ok, lower, upper, tol, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkInt #' @export testInt = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps)) { res = .Call("c_check_int", x, na.ok, lower, upper, tol, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkIntegerish.r0000644000175100001440000000323512514153643015706 0ustar hornikusers#' Check if an object is an integerish vector #' #' @templateVar fn Integerish #' @template x #' @template na-handling #' @inheritParams checkInteger #' @inheritParams checkVector #' @template tol #' @template checker #' @family basetypes #' @useDynLib checkmate c_is_integerish #' @export #' @examples #' testIntegerish(1L) #' testIntegerish(1.) #' testIntegerish(1:2, lower = 1L, upper = 2L, any.missing = FALSE) checkIntegerish = function(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_integerish", x, tol, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkIntegerish #' @useDynLib checkmate c_is_integerish #' @export assertIntegerish = function(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_integerish", x, tol, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkIntegerish #' @useDynLib checkmate c_is_integerish #' @export testIntegerish = function(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_integerish", x, tol, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/backports.r0000644000175100001440000000016712524614640014600 0ustar hornikusersif (getRversion() < "3.2.0") { dir.exists = function(paths) { x = file.info(paths)$isdir !is.na(x) & x } } checkmate/R/assert.r0000644000175100001440000000371712540747441014121 0ustar hornikusers#' Combine multiple checks into one assertion #' #' @description #' You can call this function with an arbitrary number of of \code{check*} #' functions. The resulting assertion is successful, if \code{combine} is #' \dQuote{or} (default) and at least one check evaluates to \code{TRUE} or #' \code{combine} is \dQuote{and} and all checks evaluate to \code{TRUE}. #' Otherwise, \code{assert} throws an informative error message. #' #' @param ... [any]\cr #' List of calls to check functions. #' @param combine [\code{character(1)}]\cr #' \dQuote{or} or \dQuote{and} to combine the check functions with an OR #' or AND, respectively. #' @param .var.name [character(1)]\cr #' Name of object to check. Defaults to a heuristic to determine #' the name of the first argument of the first call. #' @return Throws an error if all checks fails and invisibly returns #' \code{TRUE} otherwise. #' @export #' @examples #' x = 1:10 #' assert(checkNull(x), checkInteger(x, any.missing = FALSE)) #' \dontrun{ #' x = 1 #' assert(checkChoice(x, c("a", "b")), checkDataFrame(x)) #' } assert = function(..., combine = "or", .var.name) { assertChoice(combine, c("or", "and")) dots = match.call(expand.dots = FALSE)$... env = parent.frame() if (combine == "or") { msgs = character(length(dots)) for (i in seq_along(dots)) { val = eval(dots[[i]], envir = env) if (isTRUE(val)) return(invisible(TRUE)) msgs[i] = as.character(val) } if (missing(.var.name)) .var.name = as.character(dots[[1L]])[2L] if (length(msgs) > 1L) msgs = sprintf("%s: %s", lapply(dots, function(x) as.character(x)[1L]), msgs) mstop(qamsg(NULL, msgs, .var.name, FALSE)) } else { for (i in seq_along(dots)) { val = eval(dots[[i]], envir = env) if (!isTRUE(val)) { if (missing(.var.name)) .var.name = as.character(dots[[1L]])[2L] mstop(qamsg(NULL, val, .var.name, recursive = FALSE)) } } return(invisible(TRUE)) } } checkmate/R/checkArray.r0000644000175100001440000000274012524330563014662 0ustar hornikusers#' Check if an argument is an array #' #' @templateVar fn Array #' @template x #' @template mode #' @param any.missing [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{TRUE}. #' @param d [\code{integer(1)}]\cr #' Exact dimensionality of array \code{x}. #' Default is \code{NULL} (no check). #' @param min.d [\code{integer(1)}]\cr #' Minimum dimensionality of array \code{x}. #' Default is \code{NULL} (no check). #' @param max.d [\code{integer(1)}]\cr #' Maximum dimensionality of array \code{x}. #' Default is \code{NULL} (no check). #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_array #' @export #' @examples #' checkArray(array(1:27, dim = c(3, 3, 3)), d = 3) checkArray = function(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL) { .Call("c_check_array", x, mode, any.missing, d, min.d, max.d, PACKAGE = "checkmate") } #' @rdname checkArray #' @useDynLib checkmate c_check_array #' @export assertArray = function(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, .var.name) { res = .Call("c_check_array", x, mode, any.missing, d, min.d, max.d, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkArray #' @useDynLib checkmate c_check_array #' @export testArray = function(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL) { res = .Call("c_check_array", x, mode, any.missing, d, min.d, max.d, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkScalarNA.r0000644000175100001440000000113412514153643015225 0ustar hornikusers#' Check if an argument is a single missing value #' #' @templateVar fn ScalarNA #' @template x #' @template checker #' @family scalars #' @export #' @examples #' testScalarNA(1) #' testScalarNA(NA_real_) #' testScalarNA(rep(NA, 2)) checkScalarNA = function(x) { if (length(x) != 1L || !is.na(x)) return("Must be a scalar missing value") return(TRUE) } #' @rdname checkScalarNA #' @export assertScalarNA = function(x, .var.name) { res = checkScalarNA(x) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkScalarNA #' @export testScalarNA = function(x) { isTRUE(checkScalarNA(x)) } checkmate/R/checkPercentage.r0000644000175100001440000000172012524615212015653 0ustar hornikusers#' Check if an argument is a percentage #' #' @description #' This checks \code{x} to be numeric and in the range \code{[0,1]}. #' #' @templateVar fn Percentage #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template checker #' @family scalars #' @useDynLib checkmate c_check_number #' @export #' @examples #' testPercentage(0.5) #' testPercentage(1) checkPercentage = function(x, na.ok = FALSE) { .Call("c_check_number", x, na.ok, 0.0, 1.0, FALSE, PACKAGE = "checkmate") } #' @rdname checkPercentage #' @export assertPercentage = function(x, na.ok = FALSE, .var.name) { res = .Call("c_check_number", x, na.ok, 0.0, 1.0, FALSE, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkPercentage #' @export testPercentage = function(x, na.ok = FALSE) { res = .Call("c_check_number", x, na.ok, 0.0, 1.0, FALSE, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/isIntegerish.r0000644000175100001440000000024212514153643015237 0ustar hornikusers#' @useDynLib checkmate c_is_integerish isIntegerish = function(x, tol = sqrt(.Machine$double.eps)) { .Call("c_is_integerish", x, tol, PACKAGE = "checkmate") } checkmate/R/checkChoice.r0000644000175100001440000000132212514153643014772 0ustar hornikusers#' Check if an object is an element of a given set #' #' @templateVar fn Choice #' @template x #' @param choices [\code{atomic}]\cr #' Set of possible values. #' @template checker #' @family set #' @export #' @examples #' testChoice("x", letters) checkChoice = function(x, choices) { qassert(choices, "a") if (!qtest(x, "a1") || x %nin% choices) return(sprintf("Must be element of set {'%s'}", collapse(unique(choices), "','"))) return(TRUE) } #' @rdname checkChoice #' @export assertChoice = function(x, choices, .var.name) { res = checkChoice(x, choices) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkChoice #' @export testChoice = function(x, choices) { isTRUE(checkChoice(x, choices)) } checkmate/R/checkPathForOutput.r0000644000175100001440000000327112524615101016362 0ustar hornikusers#' @title Check file path for later output #' #' @description #' Check whether a file path can later be safely used to create a file and write to it. #' #' This is checked: #' \itemize{ #' \item{Does \code{dirname(x)} exist?} #' \item{Does no file under path \code{x} exist?} #' \item{Is \code{dirname(x)} writeable?} #' } #' Paths are relative to the current working directory. #' #' @templateVar fn PathForOutput #' @template x #' @param overwrite [\code{logical(1)}]\cr #' If \code{TRUE}, an exising file in place is allowed if it #' it is both readable and writeable. #' Default is \code{FALSE}. #' @template checker #' @family filesystem #' @export #' @examples #' # Can we create a file in the tempdir? #' testPathForOutput(file.path(tempdir(), "process.log")) checkPathForOutput = function(x, overwrite = FALSE) { if (!qtest(x, "S+")) return("No path provided") qassert(overwrite, "B1") x = normalizePath(x, mustWork = FALSE) dn = dirname(x) isdir = file.info(dn)$isdir w = wf(!file.exists(dn) || is.na(isdir)) if (length(w) > 0L) return(sprintf("Path to file (dirname) does not exist: '%s' of '%s'", dn[w], x[w])) w = which(file.exists(x)) if (overwrite) return(checkAccess(dn, "w") %and% checkAccess(x[w], "rw")) if (length(w) > 0L) return(sprintf("File at path already exists: '%s'", x[head(w, 1L)])) return(checkAccess(dn, "w")) } #' @rdname checkPathForOutput #' @export assertPathForOutput = function(x, overwrite = FALSE, .var.name) { res = checkPathForOutput(x, overwrite) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkPathForOutput #' @export testPathForOutput = function(x, overwrite = FALSE) { isTRUE(checkPathForOutput(x, overwrite)) } checkmate/R/checkSetEqual.r0000644000175100001440000000232412514153643015326 0ustar hornikusers#' Check if object is a subset of a given set #' #' @templateVar fn Subset #' @template x #' @param y [\code{atomic}]\cr #' Set to compare with. #' @param ordered [\code{logical(1)}]\cr #' Check \code{x} to have the same length and order as \code{y}, i.e. #' check using \dQuote{==} while handling \code{NA}s nicely. #' Default is \code{FALSE}. #' @template checker #' @family set #' @export #' @examples #' testSetEqual(c("a", "b"), c("a", "b")) #' testSetEqual(1:3, 1:4) checkSetEqual = function(x, y, ordered = FALSE) { qassert(x, "a") qassert(y, "a") qassert(ordered, "B1") if (ordered) { if (length(x) != length(y) || any(xor(is.na(x), is.na(y)) | x != y, na.rm = TRUE)) return(sprintf("Must be equal to {'%s'}", collapse(y, "','"))) } else { if (any(match(x, y, 0L) == 0L) || any(match(y, x, 0L) == 0L)) return(sprintf("Must be equal to set {'%s'}", collapse(y, "','"))) } return(TRUE) } #' @rdname checkSetEqual #' @export assertSetEqual = function(x, y, ordered = TRUE, .var.name) { res = checkSetEqual(x, y, ordered) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkSetEqual #' @export testSetEqual = function(x, y, ordered = TRUE) { isTRUE(checkSetEqual(x, y, ordered)) } checkmate/R/checkDataFrame.r0000644000175100001440000000315312536530034015425 0ustar hornikusers#' Check if an argument is a data frame #' #' @templateVar fn DataFrame #' @template x #' @inheritParams checkMatrix #' @inheritParams checkList #' @template checker #' @family basetypes #' @export #' @useDynLib checkmate c_check_dataframe #' @examples #' testDataFrame(iris) #' testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named") checkDataFrame = function(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) { .Call("c_check_dataframe", x, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") %and% checkListProps(x, types) } #' @rdname checkDataFrame #' @useDynLib checkmate c_check_dataframe #' @export assertDataFrame = function(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, .var.name) { res = .Call("c_check_dataframe", x, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) res = checkListProps(x, types) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkDataFrame #' @useDynLib checkmate c_check_dataframe #' @export testDataFrame = function(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) { res = .Call("c_check_dataframe", x, any.missing, min.rows, min.cols, nrows, ncols, row.names, col.names, PACKAGE = "checkmate") isTRUE(res) && isTRUE(checkListProps(x, types)) } checkmate/R/anyMissing.r0000644000175100001440000000135412524615455014735 0ustar hornikusers#' Check if an object contains missing values #' #' @description #' Supported are atomic types (see \code{\link[base]{is.atomic}}), lists and data frames. #' Missingness is defined as \code{NA} or \code{NaN} for atomic types and data frame columns, #' \code{NULL} is defined as missing for lists. #' #' @param x [\code{ANY}]\cr #' Object to check. #' @return [\code{logical(1)}] Returns \code{TRUE} if any (\code{anyMissing}) or all (\code{allMissing}) #' elements of \code{x} are missing (see details), \code{FALSE} otherwise. #' @useDynLib checkmate c_any_missing #' @export #' @examples #' anyMissing(c(1, 1)) #' anyMissing(c(1, NA)) #' anyMissing(list(1, NULL)) anyMissing = function(x) { .Call("c_any_missing", x, PACKAGE = "checkmate") } checkmate/R/checkAtomic.r0000644000175100001440000000262712524614671015031 0ustar hornikusers#' Check that an argument is an atomic vector #' #' @description #' For the definition of \dQuote{atomic}, see \code{\link[base]{is.atomic}}. #' #' @templateVar fn Atmoic #' @template x #' @inheritParams checkVector #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_atomic #' @export #' @family basetypes #' @family atomicvector #' @examples #' testAtomic(letters, min.len = 1L, any.missing = FALSE) checkAtomic = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_atomic", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkAtomic #' @useDynLib checkmate c_check_atomic #' @export assertAtomic = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_atomic", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkAtomic #' @useDynLib checkmate c_check_atomic #' @export testAtomic = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_atomic", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/wfwl.r0000644000175100001440000000031212514153643013557 0ustar hornikuserswf = function(x, use.names = TRUE) { .Call("c_which_first", x, use.names, PACKAGE = "checkmate") } wl = function(x, use.names = TRUE) { .Call("c_which_last", x, use.names, PACKAGE = "checkmate") } checkmate/R/checkAtomicVector.r0000644000175100001440000000476512535601254016214 0ustar hornikusers#' Check that an argument is an atomic vector #' #' @description #' An atomic vector is defined slightly different from specifications in #' \code{\link[base]{is.atomic}} and \code{\link[base]{is.vector}}: #' An atomic vector is either \code{logical}, \code{integer}, \code{numeric}, #' \code{complex}, \code{character} or \code{raw} and can have any attributes. #' I.e., a \code{factor} is an atomic vector, but \code{NULL} is not. #' In short, this is equivalent to \code{is.atomic(x) && !is.null(x)}. #' #' @templateVar fn AtomicVector #' @template x #' @param any.missing [\code{logical(1)}]\cr #' Are vectors with missing values allowed? Default is \code{TRUE}. #' @param all.missing [\code{logical(1)}]\cr #' Are vectors with only missing values allowed? Default is \code{TRUE}. #' @param len [\code{integer(1)}]\cr #' Exact expected length of \code{x}. #' @param min.len [\code{integer(1)}]\cr #' Minimal length of \code{x}. #' @param max.len [\code{integer(1)}]\cr #' Maximal length of \code{x}. #' @param unique [\code{logical(1)}]\cr #' Must all values be unique? Default is \code{FALSE}. #' @param names [\code{character(1)}]\cr #' Check for names. See \code{\link{checkNamed}} for possible values. #' Default is \dQuote{any} which performs no check at all. #' @template checker #' @family basetypes #' @family atomicvector #' @useDynLib checkmate c_check_atomic_vector #' @export #' @examples #' testAtomicVector(letters, min.len = 1L, any.missing = FALSE) checkAtomicVector = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_atomic_vector", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkAtomicVector #' @useDynLib checkmate c_check_atomic_vector #' @export assertAtomicVector = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_atomic_vector", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkAtomicVector #' @useDynLib checkmate c_check_atomic_vector #' @export testAtomicVector = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_atomic_vector", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkFile.r0000644000175100001440000000176412524600104014457 0ustar hornikusers#' Check existence and access rights of files #' #' @templateVar fn File #' @template x #' @inheritParams checkAccess #' @template checker #' @family filesystem #' @export #' @examples #' # Check if R's COPYING file is readable #' testFile(file.path(R.home(), "COPYING"), access = "r") #' #' # Check if R's COPYING file is readable and writable #' testFile(file.path(R.home(), "COPYING"), access = "rw") checkFile = function(x, access = "") { if (!qtest(x, "S+")) return("No file provided") d.e = dir.exists(x) w = wf(!file.exists(x) || d.e) if (length(w) > 0L) { if (d.e[w]) return(sprintf("File expected, but directory in place: '%s'", x[w])) return(sprintf("File does not exist: '%s'", x[w])) } return(checkAccess(x, access)) } #' @export #' @rdname checkFile assertFile = function(x, access = "", .var.name) { makeAssertion(checkFile(x, access), vname(x, .var.name)) } #' @rdname checkFile #' @export testFile = function(x, access = "") { isTRUE(checkFile(x, access)) } checkmate/R/qassertr.r0000644000175100001440000000247312514153643014456 0ustar hornikusers#' Quick recursive arguments checks on lists and data frames #' #' @description #' These functions are the tuned counterparts of \code{\link{qtest}} and #' \code{\link{qassert}} tailored for recursive checks of list #' elements or data frame columns. #' #' @param x [\code{list} or \code{data.frame}]\cr #' List or data frame to check for compliance with at least one of \code{rules}. #' See details of \code{\link{qtest}} for rule explanation. #' @param rules [\code{character}]\cr #' Set of rules. See \code{\link{qtest}} #' @param .var.name [\code{logical(1)}]\cr #' Argument name to print in error message. If missing, #' the name of \code{x} will be retrieved via \code{\link[base]{substitute}}. #' @return [logical(1)]: \code{TRUE} on success, \code{FALSE} (or a thrown exception) otherwise. #' @seealso \code{\link{qtest}}, \code{\link{qassert}} #' @useDynLib checkmate c_qassert #' @export #' @examples #' qtestr(as.list(1:10), "i+") #' qtestr(iris, "n") qassertr = function(x, rules, .var.name) { res = .Call("c_qassert", x, rules, TRUE, PACKAGE = "checkmate") if (!isTRUE(res)) mstop(qamsg(x, res, vname(x, .var.name), recursive = TRUE)) invisible(TRUE) } #' @rdname qassertr #' @useDynLib checkmate c_qtest #' @export qtestr = function(x, rules) { .Call("c_qtest", x, rules, TRUE, PACKAGE = "checkmate") } checkmate/R/checkVector.r0000644000175100001440000000461612536530044015051 0ustar hornikusers#' Check if an argument is a vector #' #' @templateVar fn Vector #' @template x #' @param strict [\code{logical(1)}]\cr #' May the vector have additional attributes or perform a #' check for additional attributes like \code{\link[base]{is.vector}}? #' Default is \code{FALSE} which allows e.g. \code{factor}s or \code{data.frame}s #' to be recognized as vectors. #' @param any.missing [\code{logical(1)}]\cr #' Are vectors with missing values allowed? Default is \code{TRUE}. #' @param all.missing [\code{logical(1)}]\cr #' Are vectors with only missing values allowed? Default is \code{TRUE}. #' @param len [\code{integer(1)}]\cr #' Exact expected length of \code{x}. #' @param min.len [\code{integer(1)}]\cr #' Minimal length of \code{x}. #' @param max.len [\code{integer(1)}]\cr #' Maximal length of \code{x}. #' @param unique [\code{logical(1)}]\cr #' Must all values be unique? Default is \code{FALSE}. #' @param names [\code{character(1)}]\cr #' Check for names. See \code{\link{checkNamed}} for possible values. #' Default is \dQuote{any} which performs no check at all. #' Note that you can use \code{\link{checkSubset}} to check for a specific set of names. #' @template checker #' @family basetypes #' @family atomicvector #' @useDynLib checkmate c_check_vector #' @export #' @examples #' testVector(letters, min.len = 1L, any.missing = FALSE) checkVector = function(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_vector", x, strict, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkVector #' @useDynLib checkmate c_check_vector #' @export assertVector = function(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_vector", x, strict, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkVector #' @useDynLib checkmate c_check_vector #' @export testVector = function(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_vector", x, strict, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/zzz.r0000644000175100001440000000030412514153643013436 0ustar hornikusers#' The checkmate package #' #' @section Additional information: #' #' \describe{ #' \item{Homepage:}{\url{https://github.com/mllg/checkmate}} #' } #' #' @docType package #' @name checkmate NULL checkmate/R/checkEnvironment.r0000644000175100001440000000206012514153643016104 0ustar hornikusers#' Check if an argument is an environment #' #' @templateVar fn Environment #' @template x #' @param contains [\code{character}]\cr #' Vector of object names expected in the environment. #' Defaults to \code{character(0)}. #' @template checker #' @family basetypes #' @export #' @examples #' ee = as.environment(list(a = 1)) #' testEnvironment(ee) #' testEnvironment(ee, contains = "a") checkEnvironment = function(x, contains = character(0L)) { qassert(contains, "S") if (!is.environment(x)) return("Must be an environment") if (length(contains) > 0L) { w = wf(contains %nin% ls(x, all.names = TRUE)) if (length(w) > 0L) return(sprintf("Must contain an object with name '%s'", contains[w])) } return(TRUE) } #' @rdname checkEnvironment #' @export assertEnvironment = function(x, contains = character(0L), .var.name) { res = checkEnvironment(x, contains) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkEnvironment #' @export testEnvironment = function(x, contains = character(0L)) { isTRUE(checkEnvironment(x, contains)) } checkmate/R/checkDirectory.r0000644000175100001440000000202012524600104015526 0ustar hornikusers#' Check for existence and access rights of directories #' #' @templateVar fn Directory #' @template x #' @inheritParams checkAccess #' @inheritParams checkFile #' @template checker #' @family filesystem #' @export #' @examples #' # Is R's home directory readable? #' testDirectory(R.home(), "r") #' #' # Is R's home directory readable and writable? #' testDirectory(R.home(), "rw") checkDirectory = function(x, access = "") { if (!qtest(x, "S+")) return("No directory provided") w = wf(!dir.exists(x)) if (length(w) > 0L) { if (file.exists(x[w])) return(sprintf("Directory extected, but file in place: '%s'", x[w])) return(sprintf("Directory '%s' does not exists", x[w])) } return(checkAccess(x, access)) } #' @rdname checkDirectory #' @export assertDirectory = function(x, access = "", .var.name) { res = checkDirectory(x, access) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkDirectory #' @export testDirectory = function(x, access = "", .var.name) { isTRUE(checkDirectory(x, access)) } checkmate/R/checkAccess.r0000644000175100001440000000316212524614644015011 0ustar hornikusers#' Check file system access rights #' #' @templateVar fn Access #' @template x #' @param access [\code{character(1)}]\cr #' Single string containing possible characters \sQuote{r}, \sQuote{w} and \sQuote{x} to #' force a check for read, write or execute access rights, respectively. #' Write and executable rights are not checked on Windows. #' @template checker #' @family filesystem #' @export #' @examples #' # Is R's home directory readable? #' testAccess(R.home(), "r") #' #' # Is R's home directory writeable? #' testAccess(R.home(), "w") checkAccess = function(x, access = "") { qassert(access, "S1") if (nzchar(access)) { access = match(strsplit(access, "")[[1L]], c("r", "w", "x")) if (anyMissing(access) || anyDuplicated(access) > 0L) stop("Access pattern invalid, allowed are 'r', 'w' and 'x'") if (1L %in% access) { w = wf(file.access(x, 4L) != 0L) if (length(w) > 0L) return(sprintf("'%s' not readable", x[w])) } if (.Platform$OS.type != "windows") { if (2L %in% access) { w = wf(file.access(x, 2L) != 0L) if (length(w) > 0L) return(sprintf("'%s' not writeable", x[w])) } if (3L %in% access) { w = wf(file.access(x, 1L) != 0L) if (length(w) > 0L) return(sprintf("'%s' not executeable", x[w])) } } } return(TRUE) } #' @rdname checkAccess #' @export assertAccess = function(x, access = "", .var.name) { res = checkAccess(x, access) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkAccess #' @export testAccess = function(x, access = "") { res = checkAccess(x, access) isTRUE(res) } checkmate/R/checkClass.r0000644000175100001440000000307712514153643014656 0ustar hornikusers#' Check argument inheritance #' #' @templateVar fn Class #' @template x #' @param classes [\code{character}]\cr #' Class names to check for inheritance with \code{\link[base]{inherits}}. #' @param ordered [\code{logical(1)}]\cr #' Expect \code{x} to be specialized in provided order. #' Default is \code{FALSE}. #' @template checker #' @export #' @examples #' # Create an object with classes "foo" and "bar" #' x = 1 #' class(x) = c("foo", "bar") #' #' # is x of class "foo"? #' testClass(x, "foo") #' #' # is x of class "foo" and "bar"? #' testClass(x, c("foo", "bar")) #' #' # is x most specialized as "bar"? #' testClass(x, "bar", ordered = TRUE) checkClass = function(x, classes, ordered = FALSE) { qassert(classes, "S") qassert(ordered, "B1") ord = inherits(x, classes, TRUE) w = wf(ord == 0L) if (length(w) > 0L) { cl = class(x) return(sprintf("Must have class '%s', but has class%s '%s'", classes[w], if (length(cl) > 1L) "es" else "", collapse(cl, "','"))) } if (ordered) { w = wf(ord != seq_along(ord)) if (length(w) > 0L) { cl = class(x) return(sprintf("Must have class '%s' in position %i, but has class%s '%s'", classes[w], w, if (length(cl) > 1L) "es" else "", collapse(cl, "','"))) } } return(TRUE) } #' @rdname checkClass #' @export assertClass = function(x, classes, ordered = FALSE, .var.name) { res = checkClass(x, classes, ordered) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkClass #' @export testClass = function(x, classes, ordered = FALSE) { isTRUE(checkClass(x, classes, ordered)) } checkmate/R/checkFactor.r0000644000175100001440000000767412514153643015036 0ustar hornikusers#' Check if an argument is a factor #' #' @templateVar fn Factor #' @template x #' @inheritParams checkVector #' @param levels [\code{character}]\cr #' Vector of allowed factor levels. #' @param ordered [\code{logical(1)}]\cr #' Check for an ordered factor? If \code{FALSE} or \code{TRUE}, checks explicitly #' for an unordered or ordered factor, respectively. #' Default is \code{NA} which does not perform a check. #' @param empty.levels.ok [\code{logical(1)}]\cr #' Are empty levels allowed? #' Default is \code{TRUE}. #' @param n.levels [\code{integer(1)}]\cr #' Exact number of factor levels. #' Default is \code{NULL} (no check). #' @param min.levels [\code{integer(1)}]\cr #' Minimum number of factor levels. #' Default is \code{NULL} (no check). #' @param max.levels [\code{integer(1)}]\cr #' Maximum number of factor levels. #' Default is \code{NULL} (no check). #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_factor #' @export #' @examples #' x = factor("a", levels = c("a", "b")) #' testFactor(x) #' testFactor(x, empty.levels.ok = FALSE) checkFactor = function(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL) { .Call("c_check_factor", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") %and% checkFactorProps(x, levels, ordered, empty.levels.ok, n.levels, min.levels, max.levels) } #' @rdname checkFactor #' @useDynLib checkmate c_check_factor #' @export assertFactor = function(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_factor", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) res = checkFactorProps(x, levels, ordered, empty.levels.ok, n.levels, min.levels, max.levels) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkFactor #' @useDynLib checkmate c_check_factor #' @export testFactor = function(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_factor", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) && isTRUE(checkFactorProps(x, levels, ordered, empty.levels.ok, n.levels, min.levels, max.levels)) } checkFactorProps = function(x , levels = NULL, ordered = NA, empty.levels.ok = TRUE, n.levels = NULL, min.levels = NULL, max.levels = NULL) { if (!is.null(levels)) { qassert(levels, "S") if (!setequal(levels(x), levels)) return(sprintf("Must have levels: %s", collapse(levels))) } qassert(ordered, "b1") if (!is.na(ordered)) { x.ordered = is.ordered(x) if (ordered && !x.ordered) return("Must be an ordered factor") else if (!ordered && x.ordered) return("Must be an unordered factor") } qassert(empty.levels.ok, "B1") if (!empty.levels.ok) { empty = setdiff(levels(x), levels(droplevels(x))) if (length(empty) > 0L) return(sprintf("Has has empty levels '%s'", collapse(empty, "','"))) } if (!is.null(n.levels)) { qassert(n.levels, "X1") if (length(levels(x)) != n.levels) return(sprintf("Must have exactly %i levels", n.levels)) } if (!is.null(min.levels)) { qassert(min.levels, "X1") if (length(levels(x)) < min.levels) return(sprintf("Must have at least %i levels", min.levels)) } if (!is.null(max.levels)) { qassert(max.levels, "X1") if (length(levels(x)) > max.levels) return(sprintf("Must have at most %i levels", max.levels)) } return(TRUE) } checkmate/R/checkString.r0000644000175100001440000000143512524615123015050 0ustar hornikusers#' Check if an argument is a string #' #' @description #' A string is defined as a scalar character vector. #' #' @templateVar fn String #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template checker #' @family scalars #' @export #' @useDynLib checkmate c_check_string #' @examples #' testString("a") #' testString(letters) checkString = function(x, na.ok = FALSE) { .Call("c_check_string", x, na.ok, PACKAGE = "checkmate") } #' @rdname checkString #' @export assertString = function(x, na.ok = FALSE, .var.name) { res = checkString(x, na.ok) makeAssertion(res, vname(x, .var.name)) } #' @rdname checkString #' @export testString = function(x, na.ok = FALSE) { isTRUE(checkString(x, na.ok)) } checkmate/R/checkFlag.r0000644000175100001440000000162312524614744014462 0ustar hornikusers#' Check if an argument is a flag #' #' @description #' A flag is defined as single logical value. #' #' @templateVar fn Flag #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template checker #' @family scalars #' @useDynLib checkmate c_check_flag #' @export #' @examples #' testFlag(TRUE) #' testFlag(1) checkFlag = function(x, na.ok = FALSE) { .Call("c_check_flag", x, na.ok, PACKAGE = "checkmate") } #' @rdname checkFlag #' @useDynLib checkmate c_check_flag #' @export assertFlag = function(x, na.ok = FALSE, .var.name) { res = .Call("c_check_flag", x, na.ok, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkFlag #' @useDynLib checkmate c_check_flag #' @export testFlag = function(x, na.ok = FALSE) { res = .Call("c_check_flag", x, na.ok, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkComplex.r0000644000175100001440000000244212514153643015213 0ustar hornikusers#' Check if an argument is a vector of type complex #' #' @templateVar fn Complex #' @template x #' @template na-handling #' @inheritParams checkVector #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_complex #' @export #' @examples #' testComplex(1) #' testComplex(1+1i) checkComplex = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_complex", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkComplex #' @useDynLib checkmate c_check_complex #' @export assertComplex = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_complex", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkComplex #' @useDynLib checkmate c_check_complex #' @export testComplex = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_complex", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/asInteger.r0000644000175100001440000000325012524614275014531 0ustar hornikusers#' Convert an argument to an integer #' #' @description #' \code{asInteger} is intended to be used for vectors while \code{asInt} is #' a specialization for scalar integers and \code{asCount} for scalar #' non-negative integers. #' Convertible are (a) atomic vectors with all elements \code{NA} #' and (b) double vectors with all elements being within \code{tol} #' range of an integer. #' #' @param x [any]\cr #' Object to convert. #' @param ... [any]\cr #' Additional arguments passed to \code{\link{assertIntegerish}}. #' @template tol #' @param .var.name [character(1)]\cr #' Name for \code{x}. Defaults to a heuristic to determine #' the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}. #' @return Converted \code{x}. #' @export #' @examples #' asInteger(c(1, 2, 3)) #' asCount(1) #' asInt(1) asInteger = function(x, ..., tol = sqrt(.Machine$double.eps), .var.name) { assertIntegerish(x, ..., tol = tol, .var.name = vname(x, .var.name)) storage.mode(x) = "integer" x } #' @rdname asInteger #' @param positive [\code{logical(1)}]\cr #' Must \code{x} be positive (>= 1)? #' Default is \code{FALSE}. #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @export asCount = function(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name) { assertCount(x, na.ok, positive, tol, vname(x, .var.name)) storage.mode(x) = "integer" x } #' @rdname asInteger #' @template bounds #' @export asInt = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name) { assertInt(x, na.ok, lower, upper, tol, vname(x, .var.name)) storage.mode(x) = "integer" x } checkmate/R/helper.r0000644000175100001440000000205512536237451014071 0ustar hornikusersvname = function(x, var.name) { if (!missing(var.name)) return(var.name) deparse(substitute(x, parent.frame(1L))) } makeAssertion = function(msg, var.name) { if (!isTRUE(msg)) mstop("Assertion on '%s' failed: %s", var.name, msg) invisible(TRUE) } mstop = function(msg, ...) { stop(simpleError(sprintf(msg, ...), call = sys.call(1L))) } qamsg = function(x, msg, vname, recursive=FALSE) { if (length(msg) > 1L) msg = collapse(c("One of the following must apply:", strwrap(msg, prefix = " * ")), "\n") if (recursive) { pos = attr(msg, "pos") if (testNamed(x)) { item = sprintf(", element '%s' (%i),", names(x)[pos], pos) } else { item = sprintf(", element %i,", pos) } } else { item = "" } sprintf("Assertion on '%s'%s failed. %s", vname, item, msg) } # Don't use this with assert*. Will fk up the error messages "%and%" = function(lhs, rhs) { if (isTRUE(lhs)) rhs else lhs } collapse = function(x, sep = ",") { paste0(x, collapse = sep) } "%nin%" = function(x, y) { !match(x, y, nomatch = 0L) } checkmate/R/checkLogical.r0000644000175100001440000000246212514153643015160 0ustar hornikusers#' Check if an argument is a vector of type logical #' #' @templateVar fn Logical #' @template x #' @template na-handling #' @inheritParams checkVector #' @template checker #' @family basetypes #' @useDynLib checkmate c_check_logical #' @export #' @examples #' testLogical(TRUE) #' testLogical(TRUE, min.len = 1) checkLogical = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_logical", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkLogical #' @useDynLib checkmate c_check_logical #' @export assertLogical = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_logical", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkLogical #' @useDynLib checkmate c_check_logical #' @export testLogical = function(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_logical", x, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/anyInfinite.r0000644000175100001440000000103312524614235015056 0ustar hornikusers#' Check if an object contains infinte values #' #' @description #' Supported are atomic types (see \code{\link[base]{is.atomic}}), lists and data frames. #' #' @param x [\code{ANY}]\cr #' Object to check. #' @return [\code{logical(1)}] Returns \code{TRUE} if any element if \code{-Inf} or \code{Inf}. #' @useDynLib checkmate c_any_infinite #' @export #' @examples #' anyInfinite(1:10) #' anyInfinite(c(1:10, Inf)) #' iris[3, 3] = Inf #' anyInfinite(iris) anyInfinite = function(x) { .Call("c_any_infinite", x, PACKAGE = "checkmate") } checkmate/R/checkCount.r0000644000175100001440000000225612524614721014677 0ustar hornikusers#' Check if an argument is a count #' #' @description #' A count is defined as non-negative integerish value. #' #' @templateVar fn Count #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @param positive [\code{logical(1)}]\cr #' Must \code{x} be positive (>= 1)? #' Default is \code{FALSE}, allowing 0. #' @template tol #' @template checker #' @family scalars #' @useDynLib checkmate c_check_count #' @export #' @examples #' testCount(1) #' testCount(-1) checkCount = function(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps)) { .Call("c_check_count", x, na.ok, positive, tol, PACKAGE = "checkmate") } #' @rdname checkCount #' @export assertCount = function(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name) { res = .Call("c_check_count", x, na.ok, positive, tol, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkCount #' @export testCount = function(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps)) { res = .Call("c_check_count", x, na.ok, positive, tol, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkNumber.r0000644000175100001440000000214312514153643015032 0ustar hornikusers#' Check if an argument is a single numeric #' #' @templateVar fn Number #' @template x #' @template na-handling #' @param na.ok [\code{logical(1)}]\cr #' Are missing values allowed? Default is \code{FALSE}. #' @template bounds #' @param finite [\code{logical(1)}]\cr #' Check for only finite values? Default is \code{FALSE}. #' @template checker #' @family scalars #' @useDynLib checkmate c_check_number #' @export #' @examples #' testNumber(1) #' testNumber(1:2) checkNumber = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE) { .Call("c_check_number", x, na.ok, lower, upper, finite, PACKAGE = "checkmate") } #' @rdname checkNumber #' @export assertNumber = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, .var.name) { res = .Call("c_check_number", x, na.ok, lower, upper, finite, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkNumber #' @export testNumber = function(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE) { res = .Call("c_check_number", x, na.ok, lower, upper, finite, PACKAGE = "checkmate") isTRUE(res) } checkmate/R/checkInteger.r0000644000175100001440000000302112514153643015173 0ustar hornikusers#' Check if an argument is vector of type integer #' #' @templateVar fn Integer #' @template x #' @template na-handling #' @inheritParams checkVector #' @template bounds #' @template checker #' @family basetypes #' @seealso \code{\link{asInteger}} #' @useDynLib checkmate c_check_integer #' @export #' @examples #' testInteger(1L) #' testInteger(1.) #' testInteger(1:2, lower = 1, upper = 2, any.missing = FALSE) checkInteger = function(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { .Call("c_check_integer", x, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") } #' @rdname checkInteger #' @useDynLib checkmate c_check_integer #' @export assertInteger = function(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) { res = .Call("c_check_integer", x, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") makeAssertion(res, vname(x, .var.name)) } #' @rdname checkInteger #' @useDynLib checkmate c_check_integer #' @export testInteger = function(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) { res = .Call("c_check_integer", x, lower, upper, any.missing, all.missing, len, min.len, max.len, unique, names, PACKAGE = "checkmate") isTRUE(res) } checkmate/vignettes/0000755000175100001440000000000012540757715014241 5ustar hornikuserscheckmate/vignettes/checkmate.Rmd0000644000175100001440000001536012535601411016617 0ustar hornikusers--- title: "Checkmate" author: "Michel Lang" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Vignette Title} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- Ever used an R function that produced a not-very-helpful error message, just to discover after minutes of debugging that you simply passed a wrong argument? Blaming the laziness of the package author for not doing such standard checks (in a dynamically typed language such as R) is at least partially unfair, as R makes theses types of checks cumbersome and annoying. Well, that's how it was in the past. Enter checkmate. Virtually **every standard type of user error** when passing arguments into function can be caught with a simple, readable line which produces an **informative error message** in case. A substantial part of the package was written in C to **minimize any worries about execution time overhead**. ## Intro As a motivational example, consider you have a function to calculate the faculty of a natural number and the user may choose between using either the stirling approximation or R's `factorial` function (which internally uses the gamma function). Thus, you have two arguments, `n` and `method`. Argument `n` must obviously be a positive natural number and `method` must be either `"stirling"` or `"factorial"`. Here is a version of all the hoops you need to jump through to ensure that these simple requirements are met: ```{r} fact <- function(n, method = "stirling") { if (length(n) != 1) stop("Argument 'n' must have length 1") if (!is.numeric(n)) stop("Argument 'n' must be numeric") if (is.na(n)) stop("Argument 'n' may not be NA") if (is.double(n)) { if (is.nan(n)) stop("Argument 'n' may not be NaN") if (is.infinite(n)) stop("Argument 'n' must be finite") if (abs(n - round(n, 0)) > sqrt(.Machine$double.eps)) stop("Argument 'n' must be an integerish value") n <- as.integer(n) } if (n < 0) stop("Argument 'n' must be >= 0") if (length(method) != 1) stop("Argument 'method' must have length 1") if (!is.character(method) || !method %in% c("stirling", "factorial")) stop("Argument 'method' must be either 'stirling' or 'factorial'") if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } ``` And for comparison, here is the same function using checkmate: ```{r} fact <- function(n, method = "stirling") { library(checkmate) assertCount(n) assertChoice(method, c("stirling", "factorial")) if (method == "factorial") factorial(n) else sqrt(2 * pi * n) * (n / exp(1))^n } ``` ## Function overview ### Scalars * [checkFlag](http://www.rdocumentation.org/packages/checkmate/functions/checkFlag) * [checkCount](http://www.rdocumentation.org/packages/checkmate/functions/checkCount) * [checkInt](http://www.rdocumentation.org/packages/checkmate/functions/checkInt) * [checkNumber](http://www.rdocumentation.org/packages/checkmate/functions/checkNumber) * [checkString](http://www.rdocumentation.org/packages/checkmate/functions/checkString) * [checkScalar](http://www.rdocumentation.org/packages/checkmate/functions/checkScalar) * [checkScalarNA](http://www.rdocumentation.org/packages/checkmate/functions/checkScalarNA) * [checkPercentage](http://www.rdocumentation.org/packages/checkmate/functions/checkPercentage) ### Vectors * [checkLogical](http://www.rdocumentation.org/packages/checkmate/functions/checkLogical) * [checkNumeric](http://www.rdocumentation.org/packages/checkmate/functions/checkNumeric) * [checkInteger](http://www.rdocumentation.org/packages/checkmate/functions/checkInteger) * [checkIntegerish](http://www.rdocumentation.org/packages/checkmate/functions/checkIntegerish) * [checkComplex](http://www.rdocumentation.org/packages/checkmate/functions/checkComplex) * [checkCharacter](http://www.rdocumentation.org/packages/checkmate/functions/checkCharacter) * [checkFactor](http://www.rdocumentation.org/packages/checkmate/functions/checkFactor) * [checkList](http://www.rdocumentation.org/packages/checkmate/functions/checkList) * [checkVector](http://www.rdocumentation.org/packages/checkmate/functions/checkVector) * [checkAtomic](http://www.rdocumentation.org/packages/checkmate/functions/checkAtomic) * [checkAtomicVector](http://www.rdocumentation.org/packages/checkmate/functions/checkAtomicVector) ### Attributes * [checkClass](http://www.rdocumentation.org/packages/checkmate/functions/checkClass) * [checkNames](http://www.rdocumentation.org/packages/checkmate/functions/checkNames) * [checkNamed](http://www.rdocumentation.org/packages/checkmate/functions/checkNamed) ### Choices and Subsets * [checkChoice](http://www.rdocumentation.org/packages/checkmate/functions/checkChoice) * [checkSubset](http://www.rdocumentation.org/packages/checkmate/functions/checkSubset) * [checkSetEqual](http://www.rdocumentation.org/packages/checkmate/functions/checkSetEqual) ### Matrices, Arrays and Data Frame * [checkMatrix](http://www.rdocumentation.org/packages/checkmate/functions/checkMatrix) * [checkArray](http://www.rdocumentation.org/packages/checkmate/functions/checkArray) * [checkDataFrame](http://www.rdocumentation.org/packages/checkmate/functions/checkDataFrame) ### Safe Coercion to integer * [asCount](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) * [asInt](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) * [asInteger](http://www.rdocumentation.org/packages/checkmate/functions/asInteger) ### Other builtin * [checkNull](http://www.rdocumentation.org/packages/checkmate/functions/checkNull) * [checkEnvironment](http://www.rdocumentation.org/packages/checkmate/functions/checkEnvironment) * [checkFunction](http://www.rdocumentation.org/packages/checkmate/functions/checkFunction) ### File IO: * [checkFile](http://www.rdocumentation.org/packages/checkmate/functions/checkFile) * [checkDirectory](http://www.rdocumentation.org/packages/checkmate/functions/checkDirectory) * [checkPathForOutput](http://www.rdocumentation.org/packages/checkmate/functions/checkPathForOutput) ## In case you miss flexibility You can use [assert](http://www.rdocumentation.org/packages/checkmate/functions/assert) to perform multiple checks at once and throw an assertion if all checks fail. ## Argument Checks for the Lazy The follwoing functions allow a special syntax to define argument checks using a special pattern. E.g., `qassert(x, "I+")` asserts that `x` is an integer vector with at least one element and no missing values. This provide a completely alternative mini-language (or style) how to perform argument checks. You choose what you like best. * [qassert](http://www.rdocumentation.org/packages/checkmate/functions/qassert) * [qassertr](http://www.rdocumentation.org/packages/checkmate/functions/qassert) checkmate/MD50000644000175100001440000002143412540774710012537 0ustar hornikusers0b9576bae068601a53d1a985f0fd0bad *DESCRIPTION 462cf5538633ae14d8e1edbb3fcdb8d6 *LICENSE 8dd9d74f04bdee6265968d75964beeca *NAMESPACE d581c6880c3ca1a91fccfbd2e106094f *NEWS 3ff1f93bef07b12c95e6e08d22e725bf *R/allMissing.r 22297755605465a69b0a9a139707850a *R/anyInfinite.r 3edb8ef5c44aec77d22317b137c63855 *R/anyMissing.r 5c1a3d508206f237cb673a421b4a50c4 *R/asInteger.r ddb65273c4083f179316c1291bb361e4 *R/assert.r 1a176777cc6705837865f0734a8d4746 *R/backports.r 2797a1edce86d4fe096f75370a9cb709 *R/checkAccess.r 5477211a86c85a46b765854802ab2b74 *R/checkArray.r 61d9225be228a8e1000ec368ffdfc5cb *R/checkAtomic.r fc8f8f361072cf6ec6e48efaf205f9d9 *R/checkAtomicVector.r 8758402f526b04a4def4f768551ad219 *R/checkCharacter.r d2109f8f82272ec115a31b5e632c3a3a *R/checkChoice.r 531be9a67cbdf8e0ce5647cc4a0c9eea *R/checkClass.r 8f18c99daed168a06b47f3a87b94b027 *R/checkComplex.r ef472d92c89043f6a0223e4863e43dcb *R/checkCount.r 0e6cb14f80ec0d75e1b9e04da552bddf *R/checkDataFrame.r 0734e64765b93f87eea8c9cc42ee2721 *R/checkDirectory.r 5d5a3822695fa53e5837186493dd1e43 *R/checkEnvironment.r 89e7851929ef042b8d51520709abde54 *R/checkFactor.r 89882accf35fe12c66a9edb42f3a355d *R/checkFile.r 7edd99518fba288a4d15d421928a3a5a *R/checkFlag.r 49624f87a73a1dd7add693df3436288f *R/checkFunction.r 63a335692f86f0b185f6698826bb026d *R/checkInt.r a90e9d1cdb46245df206fad0401e6bf3 *R/checkInteger.r e965162bde337b12d43f43e2d4af0dcf *R/checkIntegerish.r 24776fc83d40396ffb1e12786a1e4354 *R/checkList.r 2cd7fc17c3dcc8084fb9a28290e36e58 *R/checkLogical.r e2e1bc68656e1029d5907f66507eb6d5 *R/checkMatrix.r 29c0ee05cf19f7b0316198431d4f0592 *R/checkNamed.r c20ea7652a95094068c8fdb8b4fc4d1b *R/checkNames.r b3fd60640600dce0d718c1c92c17a088 *R/checkNull.r 1b8beb985398720d784fd4d999ff7bf0 *R/checkNumber.r cbd000bf94641fd38fadf8bc78ff45f4 *R/checkNumeric.r 0ebce292ca87ab0fc95b409dc10b9630 *R/checkPathForOutput.r e82da1b90ffb3aa7c76bed4b3707d703 *R/checkPercentage.r 013bb9bd027d0adbf82d6e990250f62b *R/checkScalar.r b9479fab5a5e08a0ed2086b7276c12c4 *R/checkScalarNA.r e8b02d53b022f0c536f382b2f16ed90f *R/checkSetEqual.r 68f2a1ac050e69bbc0f70d0e9fed8118 *R/checkString.r 9da0990c1666927940e2f2aaf89ee3ef *R/checkSubset.r 883fa771221578f8e7e99c4089885656 *R/checkVector.r 37bd8998d4faebb2ea3717cff0fbf1d6 *R/helper.r e060c7f2642e891c093e661bdfe81102 *R/isIntegerish.r f2d5057c0cd5bed8275726e5472e1576 *R/qassert.r 905707dd16a98c6bc18e758b04d53e49 *R/qassertr.r 957139c8249fe95e3a70ea52b6f5d2f6 *R/wfwl.r c397778a85c1f16788db22c604a26bd1 *R/zzz.r cf9214bdd39d8c47c9c0cf3a2d912ef2 *build/vignette.rds 308908fb8ee48e0ad210140d579f5877 *inst/doc/checkmate.R aa7530d1fb7950aca7e165c461661f46 *inst/doc/checkmate.Rmd 2fb4fcccad80981a659cfa05d62357cd *inst/doc/checkmate.html bac7c8929e4061e43f2eb3588d8de9e3 *man/anyInfinite.Rd 09139b9338450dd757d1c4cfd7ef2a8a *man/anyMissing.Rd c3e96650f3fc4aa7eace0fe72d1b2867 *man/asInteger.Rd 7028305f51586ca894a4832bacc17801 *man/assert.Rd 755554d821d1f93b6c4324ea7f159529 *man/checkAccess.Rd 8e34cf689fa64382cd33713a18e896de *man/checkArray.Rd fd26d96488411881672865222c0fcc79 *man/checkAtomic.Rd a07083f38c5a482eb94534f857504953 *man/checkAtomicVector.Rd a1ce0a762e8e8ad70a14268de5c2e566 *man/checkCharacter.Rd fd8320ca3aab71a71e1b70b3166c1a64 *man/checkChoice.Rd 1135c276874aff686b53f9c078a8cbc6 *man/checkClass.Rd 18fe44dd02a92bb0588f5b3ec7c1cfff *man/checkComplex.Rd d6ecc5d95be9c62d4464da0ed3ce1fb4 *man/checkCount.Rd 8fecf012a5cbc2bedb6720e8701bd71f *man/checkDataFrame.Rd 7d735091dce6a2fa57bf6d132836e29b *man/checkDirectory.Rd e8676f982b59083f4832c33ed389bf99 *man/checkEnvironment.Rd db34120d9703aa8e07b1dc782f024563 *man/checkFactor.Rd e4eb34beb314c80a8155f0c5bb397f8c *man/checkFile.Rd 46b0771f17daa821c3e72896acffa520 *man/checkFlag.Rd d9314db5f6e3cb30b4f7b48abe762788 *man/checkFunction.Rd 2cf5d6b64688812380c48ec0512d4035 *man/checkInt.Rd a19030c24f37e17ec4c1072ab7bac44e *man/checkInteger.Rd 8bf3c181e1db70489bb3762e5890bd60 *man/checkIntegerish.Rd e82988f034759668211f4dea667815a9 *man/checkList.Rd 25e25b08f08431525112097e504dc539 *man/checkLogical.Rd 98e9568a23fd53f4b07083e2b2b5b5d3 *man/checkMatrix.Rd 58c03626778ef906668703e3d46241ea *man/checkNamed.Rd f44b68fa67e183e89fe23f44ecd18b77 *man/checkNames.Rd 01a7e3efdccf273c6fd53329c8d8afe9 *man/checkNull.Rd d381b915d0bf1057f79afd88ae99151e *man/checkNumber.Rd e1c29f910e2d817f8c3b53cc56928a41 *man/checkNumeric.Rd 4968c54cea0249bafa833674d1c7b949 *man/checkPathForOutput.Rd 367135f7b1b0815a39feb8056ab80b7d *man/checkPercentage.Rd 00c44bffc9c9970eabf57b46ade8e14d *man/checkScalar.Rd 864ee7ad06ae45a7c5fe1a8a450f09de *man/checkScalarNA.Rd 3b405e9c01797d0da60c47ec47bca378 *man/checkSetEqual.Rd eee5d739718ae06b3ef008883ffae421 *man/checkString.Rd 86d22f642b5499fea26180ad47d6c0ac *man/checkSubset.Rd e607169143d7747738e81f9629ea0e1a *man/checkVector.Rd 176f7cc1eb31506e33a32ec271bf7435 *man/checkmate.Rd 536e895cfc10fc144a0b591ad3b53307 *man/qassert.Rd 78a163cd9edad7875f1acb773ab330c0 *man/qassertr.Rd 23522a6faf4128b56081bdbca69f54bf *src/all_missing.c 7bd9497e4946eed42b9e7d0aa7458632 *src/all_missing.h 167c7856a675e1f76902e46c94e757f4 *src/all_nchar.c 4eab07b9e951e134fca68f6b1e2acca5 *src/all_nchar.h 349a73dc8a84fc61a9ad63beec657d46 *src/any_infinite.c 847a7ba6224781bbb7777fd402c61ab5 *src/any_infinite.h cbf5a23cc322a60173586a76d2fc67fa *src/any_missing.c a393883235998ebf15eac39e29dade30 *src/any_missing.h 6595691ddf22f3d39064e9badea308ff *src/checks.c 7525d9c3ca4070ced3096d81f80f10dd *src/checks.h 9efbe813ef23801e1b513493671d3055 *src/cmessages.c c54eb02b7557579db42718835922c2d5 *src/cmessages.h a0a63402cfdf2a457544a78e3337c82c *src/helper.c d0122a5bbc8637118fe79ec836308780 *src/helper.h 99d7240b80f090cc38ebb53225b43032 *src/is_integerish.c 6f8f888b54646a57e11c3eabd05953cb *src/is_integerish.h e16321ae3ede63ad39290f3802d1bcca *src/qassert.c bededdba096cf25487848d91395ae651 *src/qassert.h f21bf53844881e843dfb5cd4014b117f *src/which_first.c 814f2931aeac2a2d485405faaacbe875 *src/which_first.h 44694bd86ba5d694433561ccfac56fc5 *tests/test-all.r afa9447fd00ef2e7aae0e8211834e72c *tests/testthat/helper.r 88a300e6dcc491c577f62eb8d664dcd9 *tests/testthat/test_anyInfinite.r 48f77a36a97f623b9ac9ca54a365f55d *tests/testthat/test_anyMissing.r bffb17b5b3dca851807563e6ab6c71e1 *tests/testthat/test_asType.r 5a524638be6c41c7ded64560177d95ae *tests/testthat/test_assert.r 89ec8ec1635aa863e196229261befa67 *tests/testthat/test_checkArray.r 92f0bb5a433f949ec95fb45898b82620 *tests/testthat/test_checkAtomic.r 0b6eb120aae82d63f8e50609ce238989 *tests/testthat/test_checkAtomicVector.r ae63f59e87c1e2f37dbfb5386cec22a4 *tests/testthat/test_checkCharacter.r b103fe816fc5b1d63f7eff1c042e1fdc *tests/testthat/test_checkChoice.R 31d63e0a5ae9cc458c1e782a052a2ce9 *tests/testthat/test_checkClass.r f30ef7df2b7617de4005f39f31e1c20d *tests/testthat/test_checkComplex.r 74a5046f037d837c773d232a9bb14a75 *tests/testthat/test_checkCount.r efe876c1d448e9ab00852550cf94a124 *tests/testthat/test_checkDataFrame.r 9a77d4935ab496691a5c8de43ca17927 *tests/testthat/test_checkEnvironment.r baa7e2bef4696f17b86034852ec36f58 *tests/testthat/test_checkFactor.r 6a24aaee93759a1ef2e6ccbec03af3a9 *tests/testthat/test_checkFilesystem.r 619eaafc2843a36bf6b56757b3430d2f *tests/testthat/test_checkFlag.r 33952d1ae05a417537459f65b0c67219 *tests/testthat/test_checkFunction.r 8a407273b9c5eb3ad936971de8d5bc79 *tests/testthat/test_checkInt.r 02198e1d75ffec160184490fadec283b *tests/testthat/test_checkInteger.r 0648282ad1e40c8c7bb7c5215d535e5b *tests/testthat/test_checkIntegerish.r 7d56a9251060b65aa7a53cec7a889040 *tests/testthat/test_checkList.r 7edbbf40d4908346442de5589d5f05a5 *tests/testthat/test_checkLogical.r 74aad071189cf45799cfc8760efbcdfd *tests/testthat/test_checkMatrix.r 63b0817d329fb0786e15f1a932aca6d6 *tests/testthat/test_checkNamed.r 693a87018c69a4e54ab96ce99ab0962a *tests/testthat/test_checkNames.r 56b3f5742f962eaa7935b609ade2802c *tests/testthat/test_checkNull.r d3eaf611b0e6be5b52259a0d5be28842 *tests/testthat/test_checkNumber.r 1a27e57a9289f3ff077e6aeb6520e31a *tests/testthat/test_checkNumeric.r d0ad02b0dea46a6db134413e8b636828 *tests/testthat/test_checkPercentage.r 87719b4defcaf295f30740ef64217966 *tests/testthat/test_checkScalar.r 6b59e2d61f45cecced0e14a54288bf59 *tests/testthat/test_checkScalarNA.r c5b3ba70bec2bcc5fe7e8a6a7eea4ef6 *tests/testthat/test_checkSetEqual.r c7dfb4fa17c998b31813509d15eca95a *tests/testthat/test_checkString.r 71428d5f6077dbd8805495e8372f07e5 *tests/testthat/test_checkSubset.r b597fd8748a8eef15fc29ce60b5c19d0 *tests/testthat/test_checkVector.r 8753de609ab6604b57b1c752ccf6b7d0 *tests/testthat/test_deparse.r 2458b1c3a4c153e148bbe704aa06a999 *tests/testthat/test_guessType.r cfd7d73824f7614b0a09ab1b0b60ab68 *tests/testthat/test_qtest.r 8884c22ae0b31281996fe70a88eba44d *tests/testthat/test_qtestr.r 4044fb9c5529ef08e3e5e75cf68c8073 *tests/testthat/test_wf.r 73143a8d044c6379d3f2aaf269fabdf1 *tests/testthat/test_wfwl.r aa7530d1fb7950aca7e165c461661f46 *vignettes/checkmate.Rmd checkmate/build/0000755000175100001440000000000012540757715013330 5ustar hornikuserscheckmate/build/vignette.rds0000644000175100001440000000031712540757715015670 0ustar hornikusersb```b`f@&0`b fd`aҼٹ%zA)h|ay%% !%9%9hH (&$yh]R RR@g;<E T [&#P{!p\ܠL t7`~΢r=xA$Gs=ʕXVr70߶checkmate/DESCRIPTION0000644000175100001440000000136412540774710013735 0ustar hornikusersPackage: checkmate Type: Package 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: 1.6.0 Author: Michel Lang , Bernd Bischl Maintainer: Michel Lang URL: https://github.com/mllg/checkmate BugReports: https://github.com/mllg/checkmate/issues NeedsCompilation: yes ByteCompile: yes Encoding: UTF-8 Depends: R (>= 3.0.0) Suggests: testthat, knitr License: BSD_3_clause + file LICENSE VignetteBuilder: knitr Packaged: 2015-06-19 09:24:29 UTC; lang Repository: CRAN Date/Publication: 2015-06-19 13:15:20 checkmate/man/0000755000175100001440000000000012524324060012765 5ustar hornikuserscheckmate/man/checkIntegerish.Rd0000644000175100001440000001015412536530203016355 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkIntegerish.r \name{checkIntegerish} \alias{assertIntegerish} \alias{checkIntegerish} \alias{testIntegerish} \title{Check if an object is an integerish vector} \usage{ checkIntegerish(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertIntegerish(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testIntegerish(x, tol = sqrt(.Machine$double.eps), lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{tol}{[\code{double(1)}]\cr Numerical tolerance used to check whether a double or complex can be converted. Default is \code{sqrt(.Machine$double.eps)}.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertIntegerish} throws an error message, \code{testIntegerish} returns \code{FALSE} and \code{checkIntegerish} returns a string with the error message. } \description{ Check if an object is an integerish vector } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testIntegerish(1L) testIntegerish(1.) testIntegerish(1:2, lower = 1L, upper = 2L, any.missing = FALSE) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkCharacter.Rd0000644000175100001440000001046212536530203016152 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkCharacter.r \name{checkCharacter} \alias{assertCharacter} \alias{checkCharacter} \alias{testCharacter} \title{Check if an argument is a vector of type character} \usage{ checkCharacter(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertCharacter(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testCharacter(x, min.chars = NULL, pattern = NULL, fixed = FALSE, ignore.case = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{min.chars}{[\code{integer(1)}]\cr Minimum number of characters in each element of \code{x}.} \item{pattern}{[\code{character(1L)}]\cr Regular expression as used in \code{\link[base]{grepl}}. All elements of \code{x} must comply to this pattern. Defaults to \code{NULL}.} \item{fixed}{[\code{logical(1)}]\cr See \code{\link[base]{grepl}}. Default is \code{FALSE}.} \item{ignore.case}{[\code{logical(1)}]\cr See \code{\link[base]{grepl}}. Default is \code{FALSE}.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertCharacter} throws an error message, \code{testCharacter} returns \code{FALSE} and \code{checkCharacter} returns a string with the error message. } \description{ Check if an argument is a vector of type character } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testCharacter(letters, min.len = 1, any.missing = FALSE) testCharacter(letters, min.chars = 2) testCharacter("example", pattern = "xa") } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkNames.Rd0000644000175100001440000000302712536530203015320 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkNames.r \name{checkNames} \alias{assertNames} \alias{checkNames} \alias{testNames} \title{Check names to comply to specific rules} \usage{ checkNames(x, type = "named") assertNames(x, type = "named", .var.name) testNames(x, type = "named") } \arguments{ \item{x}{[\code{character} || \code{NULL}]\cr Names to check using rules defined via \code{type}.} \item{type}{[character(1)]\cr Select the check(s) to perform. \dQuote{unnamed} checks \code{x} to be \code{NULL}. \dQuote{named} (default) checks \code{x} for reguluar names which excludes names to be \code{NA} or emtpy (\code{""}). \dQuote{unique} additionally tests for non-duplicated names. \dQuote{strict} checks for unique names which comply to R's variable name restrictions. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertNamed} throws an error message, \code{testNamed} returns \code{FALSE} and \code{checkNamed} returns a string with the error message. } \description{ Similar to \code{\link{checkNamed}} but you can pass the names directly. } \examples{ x = 1:3 testNames(x, "unnamed") names(x) = letters[1:3] testNames(x, "unique") } checkmate/man/qassert.Rd0000644000175100001440000001011412536546070014745 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/qassert.r \name{qassert} \alias{qassert} \alias{qtest} \title{Quick argument checks on (builtin) R types} \usage{ qassert(x, rules, .var.name) qtest(x, rules) } \arguments{ \item{x}{[any]\cr Object the check.} \item{rules}{[\code{character}]\cr Set of rules. See details.} \item{.var.name}{[\code{logical(1)}]\cr Argument name to print in error message. If missing, the name of \code{x} will be retrieved via \code{\link[base]{substitute}}.} } \value{ [logical(1)]: \code{TRUE} on success, \code{FALSE} (or a thrown exception) otherwise. } \description{ The provided functions parse rules which allow to express some of the most frequent argument checks by typing just a few letters. } \details{ \code{qassert} throws an \code{R} exception if object \code{x} does not comply to at least one of the \code{rules} and returns \code{TRUE} otherwise. \code{qtest} behaves the same way but returns \code{FALSE} if none of the \code{rules} comply. The rule is specified in up to three parts. \enumerate{ \item{ Class and missingness check. The first letter is an abbreviation for the class. If it is provided uppercase, missing values are prohibited. Supported abbreviations: \tabular{rl}{ \code{[bB]} \tab Bool / logical.\cr \code{[iI]} \tab Integer.\cr \code{[xX]} \tab Integerish (numeric convertible to integer, see \code{\link{checkIntegerish}}).\cr \code{[rR]} \tab Real / double.\cr \code{[cC]} \tab Complex.\cr \code{[nN]} \tab Numeric (integer or double).\cr \code{[sS]} \tab String / character.\cr \code{[aA]} \tab Atomic.\cr \code{[vV]} \tab Atomic vector (see \code{\link{checkAtomicVector}}).\cr \code{[lL]} \tab List. Missingness is defined as \code{NULL} element.\cr \code{[mM]} \tab Matrix.\cr \code{[dD]} \tab Data.frame. Missingness is checked recursively on columns.\cr \code{[e]} \tab Environment.\cr \code{[f]} \tab Function.\cr \code{[0]} \tab \code{NULL}.\cr \code{[*]} \tab placeholder to allow any type. } Note that the check for missingness does not distinguish between \code{NaN} and \code{NA}. Infinite values are not treated as missing, but can be catched using boundary checks (part 3). } \item{ Length definition. This can be one of \tabular{rl}{ \code{[*]} \tab any length,\cr \code{[?]} \tab length of zero or one,\cr \code{[+]} \tab length of at least one, or\cr \code{[0-9]+} \tab exact length specified as integer. } Preceding the exact length with one of the comparison operators \code{=}/\code{==}, \code{<}, \code{<=}, \code{>=} or \code{>} is also supported. } \item{ Range check as two numbers separated by a comma, enclosed by square brackets (endpoint included) or parentheses (endpoint excluded). For example, \dQuote{[0, 3)} would trigger the check \code{all(x >= 0 & x < 3)}. Endpoints may be omitted which is the equivalent of an infinite endpoint. By definition \code{[0,]} contains \code{Inf}, while \code{[0,)} does not. The same holds for the left (lower) endpoint and \code{-Inf}. E.g., the rule \dQuote{N1()} checks for a single finite numeric which is not NA, while \dQuote{N1[)} would allow \code{-Inf}. } } } \note{ The functions are inspired by the blog post of Bogumił Kamiński: \url{http://rsnippets.blogspot.de/2013/06/testing-function-agruments-in-gnu-r.html}. The implementation is mostly written in C to minimize the overhead. } \examples{ # logical of length 1 qtest(NA, "b1") # logical of length 1, NA not allowed qtest(NA, "B1") # logical of length 0 or 1, NA not allowed qtest(TRUE, "B?") # numeric with length > 0 qtest(runif(10), "n+") # integer with length > 0, NAs not allowed, all integers >= 0 and < Inf qtest(1:3, "I+[0,)") # either an emtpy list or a character vector with <=5 elements qtest(1, c("l0", "s<=5")) # data frame with at least one column and no missing value in any column qtest(iris, "D+") } \seealso{ \code{\link{qtestr}} and \code{\link{qassertr}} for efficient checks of list elements and data frame columns. } checkmate/man/checkPathForOutput.Rd0000644000175100001440000000340512524615277017055 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkPathForOutput.r \name{checkPathForOutput} \alias{assertPathForOutput} \alias{checkPathForOutput} \alias{testPathForOutput} \title{Check file path for later output} \usage{ checkPathForOutput(x, overwrite = FALSE) assertPathForOutput(x, overwrite = FALSE, .var.name) testPathForOutput(x, overwrite = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{overwrite}{[\code{logical(1)}]\cr If \code{TRUE}, an exising file in place is allowed if it it is both readable and writeable. Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertPathForOutput} throws an error message, \code{testPathForOutput} returns \code{FALSE} and \code{checkPathForOutput} returns a string with the error message. } \description{ Check whether a file path can later be safely used to create a file and write to it. This is checked: \itemize{ \item{Does \code{dirname(x)} exist?} \item{Does no file under path \code{x} exist?} \item{Is \code{dirname(x)} writeable?} } Paths are relative to the current working directory. } \examples{ # Can we create a file in the tempdir? testPathForOutput(file.path(tempdir(), "process.log")) } \seealso{ Other filesystem: \code{\link{assertAccess}}, \code{\link{checkAccess}}, \code{\link{testAccess}}; \code{\link{assertDirectory}}, \code{\link{checkDirectory}}, \code{\link{testDirectory}}; \code{\link{assertFile}}, \code{\link{checkFile}}, \code{\link{testFile}} } checkmate/man/checkArray.Rd0000644000175100001440000000627312524330443015342 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkArray.r \name{checkArray} \alias{assertArray} \alias{checkArray} \alias{testArray} \title{Check if an argument is an array} \usage{ checkArray(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL) assertArray(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL, .var.name) testArray(x, mode = NULL, any.missing = TRUE, d = NULL, min.d = NULL, max.d = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{mode}{[\code{character(1)}]\cr Storage mode of the array. Arrays can hold vectors, i.e. \dQuote{logical}, \dQuote{integer}, \dQuote{double}, \dQuote{numeric}, \dQuote{complex}, \dQuote{character} and \dQuote{list}. You can also specify \dQuote{atomic} here to explicitly prohibit lists. Default is \code{NULL} (no check).} \item{any.missing}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{TRUE}.} \item{d}{[\code{integer(1)}]\cr Exact dimensionality of array \code{x}. Default is \code{NULL} (no check).} \item{min.d}{[\code{integer(1)}]\cr Minimum dimensionality of array \code{x}. Default is \code{NULL} (no check).} \item{max.d}{[\code{integer(1)}]\cr Maximum dimensionality of array \code{x}. Default is \code{NULL} (no check).} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertArray} throws an error message, \code{testArray} returns \code{FALSE} and \code{checkArray} returns a string with the error message. } \description{ Check if an argument is an array } \examples{ checkArray(array(1:27, dim = c(3, 3, 3)), d = 3) } \seealso{ Other basetypes: \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/anyMissing.Rd0000644000175100001440000000155212524615465015414 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/allMissing.r, R/anyMissing.r \name{allMissing} \alias{allMissing} \alias{anyMissing} \title{Check if an object contains missing values} \usage{ allMissing(x) anyMissing(x) } \arguments{ \item{x}{[\code{ANY}]\cr Object to check.} } \value{ [\code{logical(1)}] Returns \code{TRUE} if any (\code{anyMissing}) or all (\code{allMissing}) elements of \code{x} are missing (see details), \code{FALSE} otherwise. } \description{ Supported are atomic types (see \code{\link[base]{is.atomic}}), lists and data frames. Missingness is defined as \code{NA} or \code{NaN} for atomic types and data frame columns, \code{NULL} is defined as missing for lists. } \examples{ allMissing(1:2) allMissing(c(1, NA)) allMissing(c(NA, NA)) anyMissing(c(1, 1)) anyMissing(c(1, NA)) anyMissing(list(1, NULL)) } checkmate/man/checkString.Rd0000644000175100001440000000344412524615277015542 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkString.r \name{checkString} \alias{assertString} \alias{checkString} \alias{testString} \title{Check if an argument is a string} \usage{ checkString(x, na.ok = FALSE) assertString(x, na.ok = FALSE, .var.name) testString(x, na.ok = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertString} throws an error message, \code{testString} returns \code{FALSE} and \code{checkString} returns a string with the error message. } \description{ A string is defined as a scalar character vector. } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testString("a") testString(letters) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}} } checkmate/man/assert.Rd0000644000175100001440000000224412536237605014572 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/assert.r \name{assert} \alias{assert} \title{Combine multiple checks into one assertion} \usage{ assert(..., combine = "or", .var.name) } \arguments{ \item{...}{[any]\cr List of calls to check functions.} \item{combine}{[\code{character(1)}]\cr \dQuote{or} or \dQuote{and} to combine the check functions with an OR or AND, respectively.} \item{.var.name}{[character(1)]\cr Name of object to check. Defaults to a heuristic to determine the name of the first argument of the first call.} } \value{ Throws an error if all checks fails and invisibly returns \code{TRUE} otherwise. } \description{ You can call this function with an arbitrary number of of \code{check*} functions. The resulting assertion is successful, if \code{combine} is \dQuote{or} (default) and at least one check evaluates to \code{TRUE} or \code{combine} is \dQuote{and} and all checks evaluate to \code{TRUE}. Otherwise, \code{assert} throws an informative error message. } \examples{ x = 1:10 assert(checkNull(x), checkInteger(x, any.missing = FALSE)) \dontrun{ x = 1 assert(checkChoice(x, c("a", "b")), checkDataFrame(x)) } } checkmate/man/checkAtomic.Rd0000644000175100001440000001165012536530203015472 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkAtomic.r \name{checkAtomic} \alias{assertAtomic} \alias{checkAtomic} \alias{testAtomic} \title{Check that an argument is an atomic vector} \usage{ checkAtomic(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertAtomic(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testAtomic(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertAtmoic} throws an error message, \code{testAtmoic} returns \code{FALSE} and \code{checkAtmoic} returns a string with the error message. } \description{ For the definition of \dQuote{atomic}, see \code{\link[base]{is.atomic}}. } \examples{ testAtomic(letters, min.len = 1L, any.missing = FALSE) } \seealso{ Other atomicvector: \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkChoice.Rd0000644000175100001440000000226112524117441015450 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkChoice.r \name{checkChoice} \alias{assertChoice} \alias{checkChoice} \alias{testChoice} \title{Check if an object is an element of a given set} \usage{ checkChoice(x, choices) assertChoice(x, choices, .var.name) testChoice(x, choices) } \arguments{ \item{x}{[any]\cr Object to check.} \item{choices}{[\code{atomic}]\cr Set of possible values.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertChoice} throws an error message, \code{testChoice} returns \code{FALSE} and \code{checkChoice} returns a string with the error message. } \description{ Check if an object is an element of a given set } \examples{ testChoice("x", letters) } \seealso{ Other set: \code{\link{assertSetEqual}}, \code{\link{checkSetEqual}}, \code{\link{testSetEqual}}; \code{\link{assertSubset}}, \code{\link{checkSubset}}, \code{\link{testSubset}} } checkmate/man/checkNumeric.Rd0000644000175100001440000000770012536530203015661 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkNumeric.r \name{checkNumeric} \alias{assertNumeric} \alias{checkNumeric} \alias{testNumeric} \title{Check that an argument is a vector of type numeric} \usage{ checkNumeric(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertNumeric(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testNumeric(x, lower = -Inf, upper = Inf, finite = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} \item{finite}{[\code{logical(1)}]\cr Check for only finite values? Default is \code{FALSE}.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertNumeric} throws an error message, \code{testNumeric} returns \code{FALSE} and \code{checkNumeric} returns a string with the error message. } \description{ Check that an argument is a vector of type numeric } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testNumeric(1) testNumeric(1, min.len = 1, lower = 0) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkNull.Rd0000644000175100001440000000153412524117441015172 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkNull.r \name{checkNull} \alias{assertNull} \alias{checkNull} \alias{testNull} \title{Check if an argument is NULL} \usage{ checkNull(x) assertNull(x, .var.name) testNull(x) } \arguments{ \item{x}{[any]\cr Object to check.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertNull} throws an error message, \code{testNull} returns \code{FALSE} and \code{checkNull} returns a string with the error message. } \description{ Check if an argument is NULL } \examples{ testNull(NULL) testNull(1) } checkmate/man/checkDataFrame.Rd0000644000175100001440000001024012536530203016074 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkDataFrame.r \name{checkDataFrame} \alias{assertDataFrame} \alias{checkDataFrame} \alias{testDataFrame} \title{Check if an argument is a data frame} \usage{ checkDataFrame(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) assertDataFrame(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, .var.name) testDataFrame(x, types = character(0L), any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{types}{[\code{character}]\cr Character vector of class names. Each list element must inherit from at least one of the provided types. The types \dQuote{logical}, \dQuote{integer}, \dQuote{integerish}, \dQuote{double}, \dQuote{numeric}, \dQuote{complex}, \dQuote{character}, \dQuote{factor}, \dQuote{atomic}, \dQuote{vector} \dQuote{atomicvector}, \dQuote{array}, \dQuote{matrix}, \dQuote{list}, \dQuote{function}, \dQuote{environment} and \dQuote{null} are supported. For other types \code{\link[base]{inherits}} is used as a fallback to check \code{x}'s inheritance. Defaults to \code{character(0)} (no check).} \item{any.missing}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{TRUE}.} \item{min.rows}{[\code{integer(1)}]\cr Minimum number of rows.} \item{min.cols}{[\code{integer(1)}]\cr Minimum number of columns.} \item{nrows}{[\code{integer(1)}]\cr Exact number of rows.} \item{ncols}{[\code{integer(1)}]\cr Exact number of columns.} \item{row.names}{[\code{character(1)}]\cr Check for row names. Default is \dQuote{NULL} (no check). See \code{\link{checkNamed}} for possible values. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{col.names}{[\code{character(1)}]\cr Check for column names. Default is \dQuote{NULL} (no check). See \code{\link{checkNamed}} for possible values. Note that you can use \code{\link{checkSubset}} to test for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertDataFrame} throws an error message, \code{testDataFrame} returns \code{FALSE} and \code{checkDataFrame} returns a string with the error message. } \description{ Check if an argument is a data frame } \examples{ testDataFrame(iris) testDataFrame(iris, types = c("numeric", "factor"), min.rows = 1, col.names = "named") } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkScalarNA.Rd0000644000175100001440000000306212524117441015702 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkScalarNA.r \name{checkScalarNA} \alias{assertScalarNA} \alias{checkScalarNA} \alias{testScalarNA} \title{Check if an argument is a single missing value} \usage{ checkScalarNA(x) assertScalarNA(x, .var.name) testScalarNA(x) } \arguments{ \item{x}{[any]\cr Object to check.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertScalarNA} throws an error message, \code{testScalarNA} returns \code{FALSE} and \code{checkScalarNA} returns a string with the error message. } \description{ Check if an argument is a single missing value } \examples{ testScalarNA(1) testScalarNA(NA_real_) testScalarNA(rep(NA, 2)) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkSetEqual.Rd0000644000175100001440000000265312524117441016006 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkSetEqual.r \name{checkSetEqual} \alias{assertSetEqual} \alias{checkSetEqual} \alias{testSetEqual} \title{Check if object is a subset of a given set} \usage{ checkSetEqual(x, y, ordered = FALSE) assertSetEqual(x, y, ordered = TRUE, .var.name) testSetEqual(x, y, ordered = TRUE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{y}{[\code{atomic}]\cr Set to compare with.} \item{ordered}{[\code{logical(1)}]\cr Check \code{x} to have the same length and order as \code{y}, i.e. check using \dQuote{==} while handling \code{NA}s nicely. Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertSubset} throws an error message, \code{testSubset} returns \code{FALSE} and \code{checkSubset} returns a string with the error message. } \description{ Check if object is a subset of a given set } \examples{ testSetEqual(c("a", "b"), c("a", "b")) testSetEqual(1:3, 1:4) } \seealso{ Other set: \code{\link{assertChoice}}, \code{\link{checkChoice}}, \code{\link{testChoice}}; \code{\link{assertSubset}}, \code{\link{checkSubset}}, \code{\link{testSubset}} } checkmate/man/checkClass.Rd0000644000175100001440000000257712524117441015335 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkClass.r \name{checkClass} \alias{assertClass} \alias{checkClass} \alias{testClass} \title{Check argument inheritance} \usage{ checkClass(x, classes, ordered = FALSE) assertClass(x, classes, ordered = FALSE, .var.name) testClass(x, classes, ordered = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{classes}{[\code{character}]\cr Class names to check for inheritance with \code{\link[base]{inherits}}.} \item{ordered}{[\code{logical(1)}]\cr Expect \code{x} to be specialized in provided order. Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertClass} throws an error message, \code{testClass} returns \code{FALSE} and \code{checkClass} returns a string with the error message. } \description{ Check argument inheritance } \examples{ # Create an object with classes "foo" and "bar" x = 1 class(x) = c("foo", "bar") # is x of class "foo"? testClass(x, "foo") # is x of class "foo" and "bar"? testClass(x, c("foo", "bar")) # is x most specialized as "bar"? testClass(x, "bar", ordered = TRUE) } checkmate/man/checkCount.Rd0000644000175100001440000000430412524615277015360 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkCount.r \name{checkCount} \alias{assertCount} \alias{checkCount} \alias{testCount} \title{Check if an argument is a count} \usage{ checkCount(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps)) assertCount(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name) testCount(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{positive}{[\code{logical(1)}]\cr Must \code{x} be positive (>= 1)? Default is \code{FALSE}, allowing 0.} \item{tol}{[\code{double(1)}]\cr Numerical tolerance used to check whether a double or complex can be converted. Default is \code{sqrt(.Machine$double.eps)}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertCount} throws an error message, \code{testCount} returns \code{FALSE} and \code{checkCount} returns a string with the error message. } \description{ A count is defined as non-negative integerish value. } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testCount(1) testCount(-1) } \seealso{ Other scalars: \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkComplex.Rd0000644000175100001440000000700412536530203015663 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkComplex.r \name{checkComplex} \alias{assertComplex} \alias{checkComplex} \alias{testComplex} \title{Check if an argument is a vector of type complex} \usage{ checkComplex(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertComplex(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testComplex(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertComplex} throws an error message, \code{testComplex} returns \code{FALSE} and \code{checkComplex} returns a string with the error message. } \description{ Check if an argument is a vector of type complex } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testComplex(1) testComplex(1+1i) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkInt.Rd0000644000175100001440000000446512524117441015020 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkInt.r \name{checkInt} \alias{assertInt} \alias{checkInt} \alias{testInt} \title{Check if an argument is a single integerish value} \usage{ checkInt(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps)) assertInt(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name) testInt(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps)) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} \item{tol}{[\code{double(1)}]\cr Numerical tolerance used to check whether a double or complex can be converted. Default is \code{sqrt(.Machine$double.eps)}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertInt} throws an error message, \code{testInt} returns \code{FALSE} and \code{checkInt} returns a string with the error message. } \description{ Check if an argument is a single integerish value } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testInt(1) testInt(-1, lower = 0) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/qassertr.Rd0000644000175100001440000000211412524117441015121 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/qassertr.r \name{qassertr} \alias{qassertr} \alias{qtestr} \title{Quick recursive arguments checks on lists and data frames} \usage{ qassertr(x, rules, .var.name) qtestr(x, rules) } \arguments{ \item{x}{[\code{list} or \code{data.frame}]\cr List or data frame to check for compliance with at least one of \code{rules}. See details of \code{\link{qtest}} for rule explanation.} \item{rules}{[\code{character}]\cr Set of rules. See \code{\link{qtest}}} \item{.var.name}{[\code{logical(1)}]\cr Argument name to print in error message. If missing, the name of \code{x} will be retrieved via \code{\link[base]{substitute}}.} } \value{ [logical(1)]: \code{TRUE} on success, \code{FALSE} (or a thrown exception) otherwise. } \description{ These functions are the tuned counterparts of \code{\link{qtest}} and \code{\link{qassert}} tailored for recursive checks of list elements or data frame columns. } \examples{ qtestr(as.list(1:10), "i+") qtestr(iris, "n") } \seealso{ \code{\link{qtest}}, \code{\link{qassert}} } checkmate/man/checkPercentage.Rd0000644000175100001440000000352612524615277016352 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkPercentage.r \name{checkPercentage} \alias{assertPercentage} \alias{checkPercentage} \alias{testPercentage} \title{Check if an argument is a percentage} \usage{ checkPercentage(x, na.ok = FALSE) assertPercentage(x, na.ok = FALSE, .var.name) testPercentage(x, na.ok = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertPercentage} throws an error message, \code{testPercentage} returns \code{FALSE} and \code{checkPercentage} returns a string with the error message. } \description{ This checks \code{x} to be numeric and in the range \code{[0,1]}. } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testPercentage(0.5) testPercentage(1) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkVector.Rd0000644000175100001440000000754512536530203015530 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkVector.r \name{checkVector} \alias{assertVector} \alias{checkVector} \alias{testVector} \title{Check if an argument is a vector} \usage{ checkVector(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertVector(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testVector(x, strict = FALSE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{strict}{[\code{logical(1)}]\cr May the vector have additional attributes or perform a check for additional attributes like \code{\link[base]{is.vector}}? Default is \code{FALSE} which allows e.g. \code{factor}s or \code{data.frame}s to be recognized as vectors.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertVector} throws an error message, \code{testVector} returns \code{FALSE} and \code{checkVector} returns a string with the error message. } \description{ Check if an argument is a vector } \examples{ testVector(letters, min.len = 1L, any.missing = FALSE) } \seealso{ Other atomicvector: \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}} Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}} } checkmate/man/checkEnvironment.Rd0000644000175100001440000000502012524117441016556 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkEnvironment.r \name{checkEnvironment} \alias{assertEnvironment} \alias{checkEnvironment} \alias{testEnvironment} \title{Check if an argument is an environment} \usage{ checkEnvironment(x, contains = character(0L)) assertEnvironment(x, contains = character(0L), .var.name) testEnvironment(x, contains = character(0L)) } \arguments{ \item{x}{[any]\cr Object to check.} \item{contains}{[\code{character}]\cr Vector of object names expected in the environment. Defaults to \code{character(0)}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertEnvironment} throws an error message, \code{testEnvironment} returns \code{FALSE} and \code{checkEnvironment} returns a string with the error message. } \description{ Check if an argument is an environment } \examples{ ee = as.environment(list(a = 1)) testEnvironment(ee) testEnvironment(ee, contains = "a") } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkSubset.Rd0000644000175100001440000000264012536530203015522 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkSubset.r \name{checkSubset} \alias{assertSubset} \alias{checkSubset} \alias{testSubset} \title{Check if object is a subset of a given set} \usage{ checkSubset(x, choices, empty.ok = TRUE) assertSubset(x, choices, empty.ok = TRUE, .var.name) testSubset(x, choices, empty.ok = TRUE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{choices}{[\code{atomic}]\cr Set of possible values.} \item{empty.ok}{[\code{logical(1)}]\cr Treat zero-length \code{x} as subset of any set \code{choices}? Default is \code{TRUE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertSubset} throws an error message, \code{testSubset} returns \code{FALSE} and \code{checkSubset} returns a string with the error message. } \description{ Check if object is a subset of a given set } \examples{ testSubset(c("a", "z"), letters) testSubset("ab", letters) testSubset("Species", names(iris)) } \seealso{ Other set: \code{\link{assertChoice}}, \code{\link{checkChoice}}, \code{\link{testChoice}}; \code{\link{assertSetEqual}}, \code{\link{checkSetEqual}}, \code{\link{testSetEqual}} } checkmate/man/checkScalar.Rd0000644000175100001440000000345012524117441015464 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkScalar.r \name{checkScalar} \alias{assertScalar} \alias{checkScalar} \alias{testScalar} \title{Check if an argument is a single atomic value} \usage{ checkScalar(x, na.ok = FALSE) assertScalar(x, na.ok = FALSE, .var.name) testScalar(x, na.ok = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertScalar} throws an error message, \code{testScalar} returns \code{FALSE} and \code{checkScalar} returns a string with the error message. } \description{ Check if an argument is a single atomic value } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testScalar(1) testScalar(1:10) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkNumber.Rd0000644000175100001440000000427612524117441015516 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkNumber.r \name{checkNumber} \alias{assertNumber} \alias{checkNumber} \alias{testNumber} \title{Check if an argument is a single numeric} \usage{ checkNumber(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE) assertNumber(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE, .var.name) testNumber(x, na.ok = FALSE, lower = -Inf, upper = Inf, finite = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} \item{finite}{[\code{logical(1)}]\cr Check for only finite values? Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertNumber} throws an error message, \code{testNumber} returns \code{FALSE} and \code{checkNumber} returns a string with the error message. } \description{ Check if an argument is a single numeric } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testNumber(1) testNumber(1:2) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertFlag}}, \code{\link{checkFlag}}, \code{\link{testFlag}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkFile.Rd0000644000175100001440000000321212524117441015132 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkFile.r \name{checkFile} \alias{assertFile} \alias{checkFile} \alias{testFile} \title{Check existence and access rights of files} \usage{ checkFile(x, access = "") assertFile(x, access = "", .var.name) testFile(x, access = "") } \arguments{ \item{x}{[any]\cr Object to check.} \item{access}{[\code{character(1)}]\cr Single string containing possible characters \sQuote{r}, \sQuote{w} and \sQuote{x} to force a check for read, write or execute access rights, respectively. Write and executable rights are not checked on Windows.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertFile} throws an error message, \code{testFile} returns \code{FALSE} and \code{checkFile} returns a string with the error message. } \description{ Check existence and access rights of files } \examples{ # Check if R's COPYING file is readable testFile(file.path(R.home(), "COPYING"), access = "r") # Check if R's COPYING file is readable and writable testFile(file.path(R.home(), "COPYING"), access = "rw") } \seealso{ Other filesystem: \code{\link{assertAccess}}, \code{\link{checkAccess}}, \code{\link{testAccess}}; \code{\link{assertDirectory}}, \code{\link{checkDirectory}}, \code{\link{testDirectory}}; \code{\link{assertPathForOutput}}, \code{\link{checkPathForOutput}}, \code{\link{testPathForOutput}} } checkmate/man/checkFlag.Rd0000644000175100001440000000340212524615277015137 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkFlag.r \name{checkFlag} \alias{assertFlag} \alias{checkFlag} \alias{testFlag} \title{Check if an argument is a flag} \usage{ checkFlag(x, na.ok = FALSE) assertFlag(x, na.ok = FALSE, .var.name) testFlag(x, na.ok = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertFlag} throws an error message, \code{testFlag} returns \code{FALSE} and \code{checkFlag} returns a string with the error message. } \description{ A flag is defined as single logical value. } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testFlag(TRUE) testFlag(1) } \seealso{ Other scalars: \code{\link{assertCount}}, \code{\link{checkCount}}, \code{\link{testCount}}; \code{\link{assertInt}}, \code{\link{checkInt}}, \code{\link{testInt}}; \code{\link{assertNumber}}, \code{\link{checkNumber}}, \code{\link{testNumber}}; \code{\link{assertPercentage}}, \code{\link{checkPercentage}}, \code{\link{testPercentage}}; \code{\link{assertScalarNA}}, \code{\link{checkScalarNA}}, \code{\link{testScalarNA}}; \code{\link{assertScalar}}, \code{\link{checkScalar}}, \code{\link{testScalar}}; \code{\link{assertString}}, \code{\link{checkString}}, \code{\link{testString}} } checkmate/man/checkInteger.Rd0000644000175100001440000000754712536530203015665 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkInteger.r \name{checkInteger} \alias{assertInteger} \alias{checkInteger} \alias{testInteger} \title{Check if an argument is vector of type integer} \usage{ checkInteger(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertInteger(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testInteger(x, lower = -Inf, upper = Inf, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertInteger} throws an error message, \code{testInteger} returns \code{FALSE} and \code{checkInteger} returns a string with the error message. } \description{ Check if an argument is vector of type integer } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testInteger(1L) testInteger(1.) testInteger(1:2, lower = 1, upper = 2, any.missing = FALSE) } \seealso{ \code{\link{asInteger}} Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkList.Rd0000644000175100001440000001013712536530203015170 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkList.r \name{checkList} \alias{assertList} \alias{checkList} \alias{testList} \title{Check if an argument is a list} \usage{ checkList(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertList(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testList(x, types = character(0L), any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{types}{[\code{character}]\cr Character vector of class names. Each list element must inherit from at least one of the provided types. The types \dQuote{logical}, \dQuote{integer}, \dQuote{integerish}, \dQuote{double}, \dQuote{numeric}, \dQuote{complex}, \dQuote{character}, \dQuote{factor}, \dQuote{atomic}, \dQuote{vector} \dQuote{atomicvector}, \dQuote{array}, \dQuote{matrix}, \dQuote{list}, \dQuote{function}, \dQuote{environment} and \dQuote{null} are supported. For other types \code{\link[base]{inherits}} is used as a fallback to check \code{x}'s inheritance. Defaults to \code{character(0)} (no check).} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} \item{...}{[ANY]\cr Additional parameters used in a call of \code{\link{checkVector}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertList} throws an error message, \code{testList} returns \code{FALSE} and \code{checkList} returns a string with the error message. } \description{ Check if an argument is a list } \examples{ testList(list()) testList(as.list(iris), types = c("numeric", "factor")) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkMatrix.Rd0000644000175100001440000000750312536530203015524 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkMatrix.r \name{checkMatrix} \alias{assertMatrix} \alias{checkMatrix} \alias{testMatrix} \title{Check if an argument is a matrix} \usage{ checkMatrix(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) assertMatrix(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL, .var.name) testMatrix(x, mode = NULL, any.missing = TRUE, min.rows = NULL, min.cols = NULL, nrows = NULL, ncols = NULL, row.names = NULL, col.names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{mode}{[\code{character(1)}]\cr Storage mode of the array. Arrays can hold vectors, i.e. \dQuote{logical}, \dQuote{integer}, \dQuote{double}, \dQuote{numeric}, \dQuote{complex}, \dQuote{character} and \dQuote{list}. You can also specify \dQuote{atomic} here to explicitly prohibit lists. Default is \code{NULL} (no check).} \item{any.missing}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{TRUE}.} \item{min.rows}{[\code{integer(1)}]\cr Minimum number of rows.} \item{min.cols}{[\code{integer(1)}]\cr Minimum number of columns.} \item{nrows}{[\code{integer(1)}]\cr Exact number of rows.} \item{ncols}{[\code{integer(1)}]\cr Exact number of columns.} \item{row.names}{[\code{character(1)}]\cr Check for row names. Default is \dQuote{NULL} (no check). See \code{\link{checkNamed}} for possible values. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{col.names}{[\code{character(1)}]\cr Check for column names. Default is \dQuote{NULL} (no check). See \code{\link{checkNamed}} for possible values. Note that you can use \code{\link{checkSubset}} to test for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertMatrix} throws an error message, \code{testMatrix} returns \code{FALSE} and \code{checkMatrix} returns a string with the error message. } \description{ Check if an argument is a matrix } \examples{ x = matrix(1:9, 3) colnames(x) = letters[1:3] testMatrix(x, nrows = 3, min.cols = 1, col.names = "named") } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkmate.Rd0000644000175100001440000000053712524117441015210 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/zzz.r \docType{package} \name{checkmate} \alias{checkmate} \alias{checkmate-package} \title{The checkmate package} \description{ The checkmate package } \section{Additional information}{ \describe{ \item{Homepage:}{\url{https://github.com/mllg/checkmate}} } } checkmate/man/checkDirectory.Rd0000644000175100001440000000321712524117441016224 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkDirectory.r \name{checkDirectory} \alias{assertDirectory} \alias{checkDirectory} \alias{testDirectory} \title{Check for existence and access rights of directories} \usage{ checkDirectory(x, access = "") assertDirectory(x, access = "", .var.name) testDirectory(x, access = "", .var.name) } \arguments{ \item{x}{[any]\cr Object to check.} \item{access}{[\code{character(1)}]\cr Single string containing possible characters \sQuote{r}, \sQuote{w} and \sQuote{x} to force a check for read, write or execute access rights, respectively. Write and executable rights are not checked on Windows.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertDirectory} throws an error message, \code{testDirectory} returns \code{FALSE} and \code{checkDirectory} returns a string with the error message. } \description{ Check for existence and access rights of directories } \examples{ # Is R's home directory readable? testDirectory(R.home(), "r") # Is R's home directory readable and writable? testDirectory(R.home(), "rw") } \seealso{ Other filesystem: \code{\link{assertAccess}}, \code{\link{checkAccess}}, \code{\link{testAccess}}; \code{\link{assertFile}}, \code{\link{checkFile}}, \code{\link{testFile}}; \code{\link{assertPathForOutput}}, \code{\link{checkPathForOutput}}, \code{\link{testPathForOutput}} } checkmate/man/anyInfinite.Rd0000644000175100001440000000106312524117441015534 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/anyInfinite.r \name{anyInfinite} \alias{anyInfinite} \title{Check if an object contains infinte values} \usage{ anyInfinite(x) } \arguments{ \item{x}{[\code{ANY}]\cr Object to check.} } \value{ [\code{logical(1)}] Returns \code{TRUE} if any element if \code{-Inf} or \code{Inf}. } \description{ Supported are atomic types (see \code{\link[base]{is.atomic}}), lists and data frames. } \examples{ anyInfinite(1:10) anyInfinite(c(1:10, Inf)) iris[3, 3] = Inf anyInfinite(iris) } checkmate/man/checkAtomicVector.Rd0000644000175100001440000000757112524601370016665 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkAtomicVector.r \name{checkAtomicVector} \alias{assertAtomicVector} \alias{checkAtomicVector} \alias{testAtomicVector} \title{Check that an argument is an atomic vector} \usage{ checkAtomicVector(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertAtomicVector(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testAtomicVector(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertAtomicVector} throws an error message, \code{testAtomicVector} returns \code{FALSE} and \code{checkAtomicVector} returns a string with the error message. } \description{ An atomic vector is defined slightly different from specifications in \code{\link[base]{is.atomic}} and \code{\link[base]{is.vector}}: An atomic vector is either \code{logical}, \code{integer}, \code{numeric}, \code{complex}, \code{character} or \code{raw} and can have any attributes. I.e., a \code{factor} is an atomic vector, but \code{NULL} is not. In short, this is equivalent to \code{is.atomic(x) && !is.null(x)}. } \examples{ testAtomicVector(letters, min.len = 1L, any.missing = FALSE) } \seealso{ Other atomicvector: \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkLogical.Rd0000644000175100001440000000702412536530203015630 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkLogical.r \name{checkLogical} \alias{assertLogical} \alias{checkLogical} \alias{testLogical} \title{Check if an argument is a vector of type logical} \usage{ checkLogical(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) assertLogical(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL, .var.name) testLogical(x, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertLogical} throws an error message, \code{testLogical} returns \code{FALSE} and \code{checkLogical} returns a string with the error message. } \description{ Check if an argument is a vector of type logical } \details{ This function does not distinguish between \code{NA}, \code{NA_integer_}, \code{NA_real_}, \code{NA_complex_} \code{NA_character_} and \code{NaN}. } \examples{ testLogical(TRUE) testLogical(TRUE, min.len = 1) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkFunction.Rd0000644000175100001440000000531712524117441016050 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkFunction.r \name{checkFunction} \alias{assertFunction} \alias{checkFunction} \alias{testFunction} \title{Check if an argument is a function} \usage{ checkFunction(x, args = NULL, ordered = FALSE) assertFunction(x, args = NULL, ordered = FALSE, .var.name) testFunction(x, args = NULL, ordered = FALSE) } \arguments{ \item{x}{[any]\cr Object to check.} \item{args}{[\code{character}]\cr Expected formal arguments. Checks that a function has no arguments if set to \code{character(0)}. Default is \code{NULL} (no check).} \item{ordered}{[\code{logical(1)}]\cr Flag whether the arguments provided in \code{args} must be the first \code{length(args)} arguments of the function in the specified order. Default is \code{FALSE}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertFunction} throws an error message, \code{testFunction} returns \code{FALSE} and \code{checkFunction} returns a string with the error message. } \description{ Check if an argument is a function } \examples{ testFunction(mean) testFunction(mean, args = "x") } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFactor}}, \code{\link{checkFactor}}, \code{\link{testFactor}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkAccess.Rd0000644000175100001440000000305712524117441015463 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkAccess.r \name{checkAccess} \alias{assertAccess} \alias{checkAccess} \alias{testAccess} \title{Check file system access rights} \usage{ checkAccess(x, access = "") assertAccess(x, access = "", .var.name) testAccess(x, access = "") } \arguments{ \item{x}{[any]\cr Object to check.} \item{access}{[\code{character(1)}]\cr Single string containing possible characters \sQuote{r}, \sQuote{w} and \sQuote{x} to force a check for read, write or execute access rights, respectively. Write and executable rights are not checked on Windows.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertAccess} throws an error message, \code{testAccess} returns \code{FALSE} and \code{checkAccess} returns a string with the error message. } \description{ Check file system access rights } \examples{ # Is R's home directory readable? testAccess(R.home(), "r") # Is R's home directory writeable? testAccess(R.home(), "w") } \seealso{ Other filesystem: \code{\link{assertDirectory}}, \code{\link{checkDirectory}}, \code{\link{testDirectory}}; \code{\link{assertFile}}, \code{\link{checkFile}}, \code{\link{testFile}}; \code{\link{assertPathForOutput}}, \code{\link{checkPathForOutput}}, \code{\link{testPathForOutput}} } checkmate/man/asInteger.Rd0000644000175100001440000000330512524117441015201 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/asInteger.r \name{asInteger} \alias{asCount} \alias{asInt} \alias{asInteger} \title{Convert an argument to an integer} \usage{ asInteger(x, ..., tol = sqrt(.Machine$double.eps), .var.name) asCount(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), .var.name) asInt(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), .var.name) } \arguments{ \item{x}{[any]\cr Object to convert.} \item{...}{[any]\cr Additional arguments passed to \code{\link{assertIntegerish}}.} \item{tol}{[\code{double(1)}]\cr Numerical tolerance used to check whether a double or complex can be converted. Default is \code{sqrt(.Machine$double.eps)}.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} \item{na.ok}{[\code{logical(1)}]\cr Are missing values allowed? Default is \code{FALSE}.} \item{positive}{[\code{logical(1)}]\cr Must \code{x} be positive (>= 1)? Default is \code{FALSE}.} \item{lower}{[\code{numeric(1)}]\cr Lower value all elements of \code{x} must be greater than.} \item{upper}{[\code{numeric(1)}]\cr Upper value all elements of \code{x} must be lower than.} } \value{ Converted \code{x}. } \description{ \code{asInteger} is intended to be used for vectors while \code{asInt} is a specialization for scalar integers and \code{asCount} for scalar non-negative integers. Convertible are (a) atomic vectors with all elements \code{NA} and (b) double vectors with all elements being within \code{tol} range of an integer. } \examples{ asInteger(c(1, 2, 3)) asCount(1) asInt(1) } checkmate/man/checkFactor.Rd0000644000175100001440000001062512536530203015475 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkFactor.r \name{checkFactor} \alias{assertFactor} \alias{checkFactor} \alias{testFactor} \title{Check if an argument is a factor} \usage{ checkFactor(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL) assertFactor(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL, .var.name) testFactor(x, levels = NULL, ordered = NA, empty.levels.ok = TRUE, any.missing = TRUE, all.missing = TRUE, len = NULL, min.len = NULL, max.len = NULL, n.levels = NULL, min.levels = NULL, max.levels = NULL, unique = FALSE, names = NULL) } \arguments{ \item{x}{[any]\cr Object to check.} \item{levels}{[\code{character}]\cr Vector of allowed factor levels.} \item{ordered}{[\code{logical(1)}]\cr Check for an ordered factor? If \code{FALSE} or \code{TRUE}, checks explicitly for an unordered or ordered factor, respectively. Default is \code{NA} which does not perform a check.} \item{empty.levels.ok}{[\code{logical(1)}]\cr Are empty levels allowed? Default is \code{TRUE}.} \item{any.missing}{[\code{logical(1)}]\cr Are vectors with missing values allowed? Default is \code{TRUE}.} \item{all.missing}{[\code{logical(1)}]\cr Are vectors with only missing values allowed? Default is \code{TRUE}.} \item{len}{[\code{integer(1)}]\cr Exact expected length of \code{x}.} \item{min.len}{[\code{integer(1)}]\cr Minimal length of \code{x}.} \item{max.len}{[\code{integer(1)}]\cr Maximal length of \code{x}.} \item{n.levels}{[\code{integer(1)}]\cr Exact number of factor levels. Default is \code{NULL} (no check).} \item{min.levels}{[\code{integer(1)}]\cr Minimum number of factor levels. Default is \code{NULL} (no check).} \item{max.levels}{[\code{integer(1)}]\cr Maximum number of factor levels. Default is \code{NULL} (no check).} \item{unique}{[\code{logical(1)}]\cr Must all values be unique? Default is \code{FALSE}.} \item{names}{[\code{character(1)}]\cr Check for names. See \code{\link{checkNamed}} for possible values. Default is \dQuote{any} which performs no check at all. Note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertFactor} throws an error message, \code{testFactor} returns \code{FALSE} and \code{checkFactor} returns a string with the error message. } \description{ Check if an argument is a factor } \examples{ x = factor("a", levels = c("a", "b")) testFactor(x) testFactor(x, empty.levels.ok = FALSE) } \seealso{ Other basetypes: \code{\link{assertArray}}, \code{\link{checkArray}}, \code{\link{testArray}}; \code{\link{assertAtomicVector}}, \code{\link{checkAtomicVector}}, \code{\link{testAtomicVector}}; \code{\link{assertAtomic}}, \code{\link{checkAtomic}}, \code{\link{testAtomic}}; \code{\link{assertCharacter}}, \code{\link{checkCharacter}}, \code{\link{testCharacter}}; \code{\link{assertComplex}}, \code{\link{checkComplex}}, \code{\link{testComplex}}; \code{\link{assertDataFrame}}, \code{\link{checkDataFrame}}, \code{\link{testDataFrame}}; \code{\link{assertEnvironment}}, \code{\link{checkEnvironment}}, \code{\link{testEnvironment}}; \code{\link{assertFunction}}, \code{\link{checkFunction}}, \code{\link{testFunction}}; \code{\link{assertIntegerish}}, \code{\link{checkIntegerish}}, \code{\link{testIntegerish}}; \code{\link{assertInteger}}, \code{\link{checkInteger}}, \code{\link{testInteger}}; \code{\link{assertList}}, \code{\link{checkList}}, \code{\link{testList}}; \code{\link{assertLogical}}, \code{\link{checkLogical}}, \code{\link{testLogical}}; \code{\link{assertMatrix}}, \code{\link{checkMatrix}}, \code{\link{testMatrix}}; \code{\link{assertNumeric}}, \code{\link{checkNumeric}}, \code{\link{testNumeric}}; \code{\link{assertVector}}, \code{\link{checkVector}}, \code{\link{testVector}} } checkmate/man/checkNamed.Rd0000644000175100001440000000275212536530203015305 0ustar hornikusers% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/checkNamed.r \name{checkNamed} \alias{assertNamed} \alias{checkNamed} \alias{testNamed} \title{Check if an argument is named} \usage{ checkNamed(x, type = "named") assertNamed(x, type = "named", .var.name) testNamed(x, type = "named") } \arguments{ \item{x}{[any]\cr Object to check.} \item{type}{[character(1)]\cr Select the check(s) to perform. \dQuote{unnamed} checks \code{x} to be unnamed. \dQuote{named} (default) checks \code{x} to be named which excludes names to be \code{NA} or emtpy (\code{""}). \dQuote{unique} additionally tests for non-duplicated names. \dQuote{strict} checks for unique names which comply to R's variable name restrictions. Note that for zero-length \code{x} every name check evalutes to \code{TRUE}. Also note that you can use \code{\link{checkSubset}} to check for a specific set of names.} \item{.var.name}{[character(1)]\cr Name for \code{x}. Defaults to a heuristic to determine the name using \code{\link[base]{deparse}} and \code{\link[base]{substitute}}.} } \value{ Depending on the function prefix: If the check is successful, all functions return \code{TRUE}. If the check is not successful, \code{assertNamed} throws an error message, \code{testNamed} returns \code{FALSE} and \code{checkNamed} returns a string with the error message. } \description{ Check if an argument is named } \examples{ x = 1:3 testNamed(x, "unnamed") names(x) = letters[1:3] testNamed(x, "unique") } checkmate/LICENSE0000644000175100001440000000011612514153643013223 0ustar hornikusersYEAR: 2014 COPYRIGHT HOLDER: Michel Lang ORGANIZATION: TU Dortmund University