Schema: Schema class

SchemaR Documentation

Schema class

Description

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.

Usage

# Schema$load(descriptor, strict = FALSE)

Arguments

descriptor

A schema descriptor; can be a JSON string, URL, or local file.

strict

Logical flag. If TRUE, validation errors are raised immediately; if FALSE, they are stored in schema$errors.

Format

R6Class object.

Value

Object of class R6Class.

Methods

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.

Returns

A Field instance if found, or NULL.

addField(descriptor)

Adds a new field to the schema.

descriptor

A list representing the field descriptor.

Raises

TableSchemaError if the field is invalid.

Returns

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.

Raises

TableSchemaError if removal causes invalid schema.

Returns

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.

Returns

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.

Returns

A schema descriptor as an object.

commit(strict)

Finalizes schema updates.

strict

Logical. Whether to enable strict validation mode.

Raises

TableSchemaError on failure.

Returns

TRUE on success; FALSE if not modified.

save(target)

Saves schema descriptor to a file.

target

File path to save the schema.

Raises

TableSchemaError on failure.

Returns

TRUE on success.

Properties

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.

Language

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.

See Also

Schema$load, Table Schema Specifications


frictionlessdata/tableschema-r documentation built on April 13, 2025, 3:51 p.m.