is_numable {labelr}R Documentation

Test Whether Character Vector Is "Suitable" for Numeric Conversion

Description

is_numable determines whether a character vector can be coerced to numeric without generating new NA values.

Usage

is_numable(x, nan2na = TRUE, inf2na = TRUE)

Arguments

x

a character vector.

nan2na

treat NaN (including, e.g., "nan") values as NA values.

inf2na

treat Inf, -Inf values (including, e.g., "inf") as NA values. treated as equivalent to NA values.

Details

Core labelr functions coerce integers to characters and back, which is_numable facilitates.

Value

a 1L (scalar) logical vector.

Examples

set.seed(123)
x1 <- runif(10)
x2 <- as.character(sample(c(1:20), 10, replace = TRUE))
x2_num_test <- is_numable(x2)
x2_num_test
x3 <- sample(LETTERS, 10, replace = TRUE)
x3_num_test <- is_numable(x3)
x3_num_test

[Package labelr version 0.1.5 Index]