Schema | R Documentation |
A model of a Table Schema with helpful methods for working with the schema and supported data.
Schema instances can be initialized using a schema source, either as a URL to a JSON file or as a JSON object.
The schema is validated upon initialization (see validate).
By default, validation errors are stored in $errors
, but in strict mode, they are raised immediately.
# Schema$load(descriptor, strict = FALSE)
descriptor |
A schema descriptor; can be a JSON string, URL, or local file. |
strict |
Logical flag. If |
R6Class
object.
Object of class R6Class
.
Schema$new(descriptor = descriptor, strict = strict)
Use Schema$load
to instantiate a Schema
class.
getField(name)
Returns a schema field by name.
name
String. Name of the schema field.
A Field
instance if found, or NULL
.
addField(descriptor)
Adds a new field to the schema.
descriptor
A list representing the field descriptor.
TableSchemaError
if the field is invalid.
The added Field
instance, or NULL
if unsuccessful.
removeField(name)
Removes a field by name from the schema.
name
Name of the field to remove.
TableSchemaError
if removal causes invalid schema.
The removed Field
instance, or NULL
.
castRow(row)
Casts a row of values based on field types and formats.
row
A list representing a data row.
The cast row as a list of typed values.
infer(rows, headers = 1)
Infers schema from given data.
rows
A list of lists representing data rows.
headers
Either a row number (index) of headers or a list of header names.
A schema descriptor as an object.
commit(strict)
Finalizes schema updates.
strict
Logical. Whether to enable strict validation mode.
TableSchemaError
on failure.
TRUE
on success; FALSE
if not modified.
save(target)
Saves schema descriptor to a file.
target
File path to save the schema.
TableSchemaError
on failure.
TRUE
on success.
valid
Returns TRUE
if schema is valid. Always TRUE
in strict mode.
errors
Returns list of validation errors. Empty in strict mode.
descriptor
Returns the full schema descriptor as a list.
primaryKey
Returns a vector of field names that compose the primary key.
foreignKeys
Returns a list of foreign key definitions.
fields
Returns list of Field
instances.
fieldNames
Returns vector of field names.
The key words MUST
, MUST NOT
, REQUIRED
, SHALL
, SHALL NOT
,
SHOULD
, SHOULD NOT
, RECOMMENDED
, MAY
, and OPTIONAL
in this documentation are interpreted as described in RFC 2119.
Schema$load
,
Table Schema Specifications
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.