assert_all_are_numeric_strings

0th

Percentile

Does the string contain a number/logical value?

Check to see if a character vector contains numeric/logical strings.

Usage
assert_all_are_numeric_strings(x, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_numeric_strings(x, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_all_are_logical_strings(x, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
assert_any_are_logical_strings(x, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))
is_numeric_string(x, .xname)
is_logical_string(x, .xname)
Arguments
x
A character vector.
na_ignore
A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
.xname
Not intended to be used directly.
Value

is_numeric_string returns a logical vector that is TRUE when the string contains numbers. The corresponding assert_* functions return nothing but throw an error on failure.

Aliases
  • assert_all_are_logical_strings
  • assert_all_are_numeric_strings
  • assert_any_are_logical_strings
  • assert_any_are_numeric_strings
  • is_logical_string
  • is_numeric_string
Examples
library(assertive.strings) is_numeric_string(c("1", "1.1", "-1.1e1", "one", NA)) # R only treats certain capitalizations of "true" and "false" as logical x <- c( "TRUE", "FALSE", "true", "false", "True", "False", "trUE", "FaLsE", "T", "F", "t", "f" ) is_logical_string(x) assert_all_are_numeric_strings(c("1", "2.3", "-4.5", "6e7", "8E-9")) assert_any_are_numeric_strings(c("1", "Not a number"))
Documentation reproduced from package assertive.strings, version 0.0-3, License: GPL (>= 3)

Community examples

Looks like there are no examples yet.