Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

type-predicates

Type predicates


Description

These type predicates aim to make type testing in R more consistent. They are wrappers around base::typeof(), so operate at a level beneath S3/S4 etc.

Usage

is_list(x, n = NULL)

is_atomic(x, n = NULL)

is_vector(x, n = NULL)

is_integer(x, n = NULL)

is_double(x, n = NULL, finite = NULL)

is_character(x, n = NULL)

is_logical(x, n = NULL)

is_raw(x, n = NULL)

is_bytes(x, n = NULL)

is_null(x)

Arguments

x

Object to be tested.

n

Expected length of a vector.

finite

Whether all values of the vector are finite. The non-finite values are NA, Inf, -Inf and NaN. Setting this to something other than NULL can be expensive because the whole vector needs to be traversed and checked.

Details

Compared to base R functions:

  • The predicates for vectors include the n argument for pattern-matching on the vector length.

  • Unlike is.atomic(), is_atomic() does not return TRUE for NULL.

  • Unlike is.vector(), is_vector() tests if an object is an atomic vector or a list. is.vector checks for the presence of attributes (other than name).

See Also


rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.