Learn R Programming

validate (version 1.1.5)

field_length: Check number of code points

Description

A convenience function testing for field length.

Usage

field_length(x, n = NULL, min = NULL, max = NULL, ...)

Value

A [logical] of size length(x).

Arguments

x

Bare (unquoted) name of a variable. Otherwise a vector of class character. Coerced to character as necessary.

n

Number of code points required.

min

Mimimum number of code points

max

Maximum number of code points

...

passed to nchar (for example type="width")

Details

The number of code points (string length) may depend on current locale settings or encoding issues, including those caused by inconsistent choices of UTF normalization.

See Also

Other format-checkers: field_format(), number_format()

Examples

Run this code

df <- data.frame(id = 11001:11003, year = c("2018","2019","2020"), value = 1:3)
rule <- validator(field_length(year, 4), field_length(id, 5))
out <- confront(df, rule) 
as.data.frame(out)

Run the code above in your browser using DataLab