Coerce character
, factor
, numeric
, logical
, and Date
vectors into fr_field
objects
Source: R/fr_field.R
as_fr_field.Rd
The supported classes of R
objects are converted to the corresponding frictionless type
:
R class | fr type |
character() | string |
factor() | string (with enum(constraints = levels(x)) ) |
numeric() , integer() | number |
logical() | boolean |
Date | date |
Arguments
- x
a character, factor, numeric, integer, logical, or Date vector
- ...
<
dynamic-dots
> required (name
) and optional (title
,description
) field descriptors)
Value
a fr_field object
Examples
as_fr_field(1:10, "example_integer") # -> frictionless number
#> example_integer
#> - type: number
as_fr_field((1:10) * 0.1, "example_double") # -> frictionless number
#> example_double
#> - type: number
as_fr_field(letters, "example_character") # -> frictionless string
#> example_character
#> - type: string
as_fr_field(factor(letters), "example_factor") # -> frictionless string with enum constraints
#> example_factor
#> - type: string
#> - constraints: enum = a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, …,
#> y, and z
as_fr_field(c(TRUE, FALSE, TRUE), "example_logical") # -> frictionless boolean
#> example_logical
#> - type: boolean
as_fr_field(as.Date(c("2023-04-23", "2004-12-31")), "example_date") # -> frictionless date
#> example_date
#> - type: date