Skip to contents

Returns TRUE when x is an atomic vector of type integer, double, character, logical, complex, or raw and has no dim attribute.

Usage

is_atomic(x)

Arguments

x

(any object)
The object to be tested.

Value

Scalar logical.

Details

This is a stricter alternative to base::is.atomic().

Only integer, double, character, logical, complex, and raw vectors return TRUE.

A dim attribute makes the result FALSE. Matrices and arrays therefore return FALSE even when their underlying type is allowed.

The test uses base::typeof(), so classed objects built on an allowed type return TRUE. This includes Date, POSIXct, and factor objects. Objects stored as lists return FALSE, including data.frame and POSIXlt.

NULL returns FALSE. Zero-length vectors of an allowed type return TRUE.

Examples

#----------------------------------------------------------------------------
# is_atomic() examples
#----------------------------------------------------------------------------
library(bkbase)

is_atomic(1)
#> [1] TRUE
is_atomic(FALSE)
#> [1] TRUE
is_atomic(c("a", "b"))
#> [1] TRUE
is_atomic(integer(0))
#> [1] TRUE
is_atomic(raw(1))
#> [1] TRUE

# FALSE because of a dim attribute
is_atomic(matrix(1))
#> [1] FALSE

# FALSE because the object is stored as a list
is_atomic(data.frame(1))
#> [1] FALSE