| Schema {tableschema.r} | R Documentation |
Schema class
Description
A model of a schema with helpful methods for working with the schema and supported data.
Schema instances can be initialized with a schema source as a url to a JSON file or a JSON object.
The schema is initially validated (see validate).
By default validation errors will be stored in $errors but in a strict mode it will be instantly raised.
Usage
# Schema.load(descriptor, strict=FALSE)
Arguments
descriptor |
schema descriptor, a JSON string, URL or file |
strict |
flag to alter validation behaviour:
|
Format
R6Class object.
Value
Object of R6Class .
Methods
Schema$new(descriptor = descriptor, strict = strict)-
Use
Schema.loadto instantiateSchemaclass. getField(name)-
Get schema field by name.
nameString with schema field name.(Field/NULL)ReturnsFieldinstance orNULLif not found.
addField(descriptor)-
Add new field to schema. The schema descriptor will be validated with newly added field descriptor.
descriptorList of field descriptor.TableSchemaErrorRaises any error occured in the process.(Field/NULL)Returns addedFieldinstance orNULLif not added.
removeField(name)-
Remove field resource by name. The schema descriptor will be validated after field descriptor removal.
nameString with schema field name.TableSchemaErrorRaises any error occured in the process.(Field/NULL)Returns removedFieldinstances orNULLif not found.
castRow(row)-
Cast row based on field types and formats.
rowData row as a list of values.(any)Returns cast data row.
infer(rows, headers=1)-
Cast row based on field types and formats.
rowsList of lists representing rows.headersdata sample headers, one of:row number containing headers (
rowsshould contain headers rows)list of headers (
rowsshould NOT contain headers rows)
{Object}Returns Table Schema descriptor.
commit(strict)-
Cast row based on field types and formats.
strictBoolean, alter strict mode for further work.TableSchemaErrorRaises any error occured in the process.(Boolean)ReturnsTRUEon success andFALSEif not modified.
save(target)-
Cast row based on field types and formats.
targetString, path where to save a descriptor.TableSchemaErrorRaises any error occured in the process.(Boolean)ReturnsTRUEon success.
Properties
validReturns validation status. It always
TRUEin strict mode.errorsReturns validation errors. It always empty in strict mode.
descriptorReturns list of schema descriptor.
primaryKeyReturns string list of schema primary key.
foreignKeysReturns list of schema foreign keys.
fieldsReturns list of
Fieldinstances.fieldNamesReturns a list of field names.
Language
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.
See Also
Schema.load,
Table Schema Specifications