checkmate (version 1.7.2)

asInteger: Convert an argument to an integer

Description

asInteger is intended to be used for vectors while asInt is a specialization for scalar integers and asCount for scalar non-negative integers. Convertible are (a) atomic vectors with all elements NA and (b) double vectors with all elements being within tol range of an integer.

Usage

asInteger(x, ..., tol = sqrt(.Machine$double.eps), add = NULL, .var.name)

asCount(x, na.ok = FALSE, positive = FALSE, tol = sqrt(.Machine$double.eps), add = NULL, .var.name)

asInt(x, na.ok = FALSE, lower = -Inf, upper = Inf, tol = sqrt(.Machine$double.eps), add = NULL, .var.name)

Arguments

x
[any] Object to convert.
...
[any] Additional arguments passed to assertIntegerish.
tol
[double(1)] Numerical tolerance used to check whether a double or complex can be converted. Default is sqrt(.Machine$double.eps).
add
[AssertCollection] Collection to store assertions. See AssertCollection.
.var.name
[character(1)] Name for x. Defaults to a heuristic to determine the name using deparse and substitute.
na.ok
[logical(1)] Are missing values allowed? Default is FALSE.
positive
[logical(1)] Must x be positive (>= 1)? Default is FALSE.
lower
[numeric(1)] Lower value all elements of x must be greater than.
upper
[numeric(1)] Upper value all elements of x must be lower than.

Value

  • Converted x.

Examples

Run this code
asInteger(c(1, 2, 3))
asCount(1)
asInt(1)

Run the code above in your browser using DataCamp Workspace