| Field | R Documentation |
Class represents field in the schema.
Data values can be cast to native R types. Casting a value will check the value is of the expected type, is in the correct format, and complies with any constraints imposed by a schema.
# Field$new(descriptor, missingValues = list(""))
descriptor |
Schema field descriptor |
missingValues |
A list with vector strings representing missing values |
base_path |
see description |
strict |
see description |
value |
see description |
constraints |
see description |
... |
see description |
R6Class object.
A field descriptor MUST be a JSON object that describes a single field.
The descriptor provides additional human-readable documentation for a field,
as well as additional information that may be used to validate the field or
create a user interface for data entry.
The field descriptor object MAY contain any number of other properties.
Some specific properties are defined below. Of these, only the name property is REQUIRED.
nameThe field descriptor MUST contain a name property.
This property SHOULD correspond to the name of field/column in the data file (if it has a name).
As such it SHOULD be unique (though it is possible, but very bad practice, for the data file to
have multiple columns with the same name). name SHOULD NOT be considered case sensitive in
determining uniqueness. However, since it should correspond to the name of the field in the data file
it may be important to preserve case.
titleA human readable label or title for the field.
descriptionA description for this field e.g. "The recipient of the funds".
Object of R6Class .
Field$new(descriptor, missingValues = list(""))Constructor to instantiate Field class.
descriptor Schema field descriptor.
missingValues A list with vector strings representing missing values.
TableSchemaError Raises any error occured in the process.
Field Returns Field class instance.
cast_value(value, constraints=TRUE)Cast given value according to the field type and format.
value Value to cast against field
constraints Gets constraints configuration:
it could be set to true to disable constraint checks, or
it could be a List of constraints to check
errors$TableSchemaError Raises any error occured in the process
any Returns cast value
testValue(value, constraints=TRUE)Test if value is compliant to the field.
value Value to cast against field
constraints Constraints configuration
Boolean Returns if value is compliant to the field
nameReturns field name
typeReturns field type
formatReturns field format
requiredReturns TRUE if field is required
constraintsReturns list with field constraints
descriptorReturns field descriptor
The key words MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT,
SHOULD, SHOULD NOT, RECOMMENDED, MAY, and OPTIONAL
in this package documents 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.