| Field | R Documentation |
Class representing a field in the schema.
Data values can be cast to native R types. Casting a value checks whether it is of the expected type, in the correct format, and compliant with any constraints imposed by the schema.
# Field$new(descriptor, missingValues = list(""))
descriptor |
Schema field descriptor. |
missingValues |
A list with vector strings representing missing values. |
R6Class object.
A field descriptor MUST be a JSON object that describes a single field. The descriptor provides both human-readable documentation and machine-readable validation rules. It may also guide user interface generation for data entry.
The descriptor object MAY include additional custom properties. Of these, only the name property is REQUIRED.
nameThe descriptor MUST contain a name property, typically corresponding to the column name in the data file. This name SHOULD be unique, and while not case-sensitive for uniqueness, preserving case is advisable.
titleA human-readable label for the field.
descriptionA text description of the field, e.g., "The recipient of the funds".
Object of class R6Class.
Field$new(descriptor, missingValues = list(""))Constructor to instantiate the Field class. Accepts the following arguments:
descriptorSchema field descriptor.
missingValuesA list of strings representing missing values.
TableSchemaErrorRaised if an error occurs during instantiation.
FieldReturns a Field class instance.
cast_value(value, constraints = TRUE)Casts a given value according to the field's type and format.
valueValue to cast.
constraintsLogical or list of constraints to apply.
errors$TableSchemaErrorRaised if casting fails due to a constraint violation.
anyReturns the cast value.
testValue(value, constraints = TRUE)Tests if a value complies with the field definition.
valueValue to test.
constraintsConstraints configuration.
BooleanReturns TRUE if the value is compliant.
nameReturns the field name.
typeReturns the field type.
formatReturns the field format.
requiredReturns TRUE if the field is required.
constraintsReturns a list of field constraints.
descriptorReturns the field descriptor.
The key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL in this documentation are to be interpreted as described in RFC 2119.
Field Descriptors Specifications
DESCRIPTOR = list(name = "height", type = "number")
field <- Field$new(descriptor = DESCRIPTOR)
# get correct instance
field$name
field$format
field$type
# return true on test
field$testValue(1)
# cast value
field$cast_value(1)
# expand descriptor by defaults
field <- Field$new(descriptor = list(name = "name"))
field$descriptor
# parse descriptor with "enum" constraint
field <- Field$new(descriptor = list(name = "status", type = "string",
constraints = list(enum = list('active', 'inactive'))))
field$testValue('active')
field$testValue('inactive')
field$testValue('activia')
field$cast_value('active')
# parse descriptor with "minimum" constraint'
field <- Field$new(descriptor = list(name = "length", type = "integer",
constraints = list(minimum = 100)))
field$testValue(200)
field$testValue(50)
# parse descriptor with "maximum" constraint'
field <- Field$new(descriptor = list(name = "length", type = "integer",
constraints = list(maximum = 100)))
field$testValue(50)
field$testValue(200)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.