to_integer: Strictly convert an object to an integer

View source: R/helper-functions.R

to_integerR Documentation

Strictly convert an object to an integer

Description

R does not have a built-in function to determine if a value is an integer (is.integer will check if the class of an object is "integer", but is.integer(3) will return FALSE). This helper function fills that gap. It will attempt to convert the input to an integer, but will error on any input that cannot be confidently expressed as an integer. It serves as a stricter version of as.integer. For example, the function will convert 3 or "3" to integers, but will error on 3.5 or "three".

Usage

to_integer(x)

Arguments

x

An input of any type.

Value

An integer interpretation of x, if possible.


ptvapi documentation built on May 29, 2024, 4:48 a.m.