Learn R Programming

chk (version 0.2.0)

chk_string: Check/Validate String or Matches

Description

Checks/validates if string or matches a regular expression.

Usage

chk_string(x, x_name = NULL)

vld_string(x, x_name = NULL)

chk_match(x, regexp = ".+", x_name = NULL)

vld_match(x, regexp = ".+")

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

regexp

A string of a regular expression.

Value

The chk_ functions throw an informative error if the test fails. The vld_ functions return a flag indicating whether the test was met.

Functions

  • chk_string: Check String

    Checks if non-missing character scalar using vld_string().

  • vld_string: Validate String

    Validates non-missing character scalar using

    is.character(x) && length(x) == 1L && !anyNA(x).

  • chk_match: Check Matches

    Checks if all values match regular expression using vld_match().

  • vld_match: Validate Matches

    Validates all values match regular expression using

    all(grepl(regexp, x)).

    regexp should be a non-missing character scalar.

See Also

all()

grepl()

Examples

Run this code
# NOT RUN {
# chk_string
chk_string("1")
try(chk_string(1))

# vld_string
vld_string("1")
vld_string("")
vld_string(1)
vld_string(NA_character_)
vld_string(c("1", "1"))

# chk_match
chk_match("1")
try(chk_match("1", regexp = "2"))

# vld_match
vld_match("1")
vld_match("a", regexp = "a")
vld_match("")
vld_match("1", regexp = "2")
vld_match(NA_character_, regexp = ".*")
# }

Run the code above in your browser using DataLab