Learn R Programming

fr (version 0.5.1)

as_fr_field: Coerce character, factor, numeric, logical, and Date vectors into fr_field objects

Description

The supported classes of R objects are converted to the corresponding frictionless type:

R classfr type
character()string
factor()string (with enum(constraints = levels(x)))
numeric(), integer()number
logical()boolean
Datedate

Usage

as_fr_field(x, ...)

Value

a fr_field object

Arguments

x

a character, factor, numeric, integer, logical, or Date vector

...

<dynamic-dots> required (name) and optional (title, description) field descriptors)

Examples

Run this code
as_fr_field(1:10, "example_integer") # -> frictionless number
as_fr_field((1:10) * 0.1, "example_double") # -> frictionless number
as_fr_field(letters, "example_character") # -> frictionless string
as_fr_field(factor(letters), "example_factor") # -> frictionless string with enum constraints
as_fr_field(c(TRUE, FALSE, TRUE), "example_logical") # -> frictionless boolean
as_fr_field(as.Date(c("2023-04-23", "2004-12-31")), "example_date") # -> frictionless date

Run the code above in your browser using DataLab