A class for working with data resources. You can read or iterate tabular resources using the iter/ read methods and all resource as bytes using rowIter/ rowRead methods.

# Resource.load(descriptor = list(), basePath = NA, strict = FALSE, dataPackage = list())

Format

R6Class object.

Value

Object of R6Class.

Methods

Resource$new(descriptor = descriptor, strict = strict)

Use Resource.load to instantiate Resource class.

iter(keyed, extended, cast = TRUE, relations = FALSE, stream = FALSE)

Only for tabular resources - Iter through the table data and emits rows cast based on table schema. Data casting could be disabled.

keyed Iter keyed rows - TRUE/ FALSE. extended Iter extended rows - TRUE/FALSE. cast Disable data casting if FALSE. relations If TRUE foreign key fields will be checked and resolved to its references. stream Return Readable Stream of table rows if TRUE.
read(keyed, extended, cast = TRUE, relations = FALSE, limit)

Only for tabular resources. Read the whole table and returns as list of rows. Count of rows could be limited.

keyed Flag to emit keyed rows - TRUE/FALSE. extended Flag to emit extended rows - TRUE/FALSE. cast Disable data casting if FALSE. relations If TRUE foreign key fields will be checked and resolved to its references. limit Integer limit of rows to return if specified.
checkRelations()

Only for tabular resources. It checks foreign keys and raises an exception if there are integrity issues. Returns TRUE if no issues.

rawIter(stream = FALSE)

Iterate over data chunks as bytes. If stream is TRUE Iterator will be returned.

stream Iterator will be returned.
rawRead()

Returns resource data as bytes.

infer()

Infer resource metadata like name, format, mediatype, encoding, schema and profile. It commits this changes into resource instance. Returns resource descriptor.

commit(strict)

Update resource instance if there are in-place changes in the descriptor. Returns TRUE on success and FALSE if not modified.

strict Boolean - Alter strict mode for further work.
save(target)

For now only descriptor will be saved. Save resource to target destination.

target String path where to save a resource.

Properties

valid

Returns validation status. It always TRUE in strict mode.

errors

Returns validation errors. It always empty in strict mode.

profile

Returns an instance of Profile class.

descriptor

Returns list of resource descriptor.

name

Returns a string of resource name.

inline

Returns TRUE if resource is inline.

local

Returns TRUE if resource is local.

remote

Returns TRUE if resource is remote.

multipart

Returns TRUE if resource is multipart.

tabular

Returns TRUE if resource is tabular.

source

Returns a list/string of data/path property respectively.

headers

Returns a string of data source headers.

schema

Returns a Schema instance to interact with data schema. Read API documentation - tableschema.Schema or Schema

Details

The Data Resource format describes a data resource such as an individual file or table. The essence of a Data Resource is a locator for the data it describes. A range of other properties can be declared to provide a richer set of metadata.

Packaged data resources are described in the resources property of the package descriptor. This property MUST be an array of objects. Each object MUST follow the Data Resource specification.

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

Methods

Public methods


Method new()

Usage

Resource$new(descriptor, basePath, strict = FALSE, dataPackage = list())


Method iter()

Usage

Resource$iter(relations = FALSE, options = list())


Method read()

Usage

Resource$read(relations = FALSE, ...)


Method checkRelations()

Usage

Resource$checkRelations()


Method rawIter()

Usage

Resource$rawIter(stream = FALSE)


Method rawRead()

Usage

Resource$rawRead()


Method infer()

Usage

Resource$infer()


Method commit()

Usage

Resource$commit(strict = NULL)


Method save()

Usage

Resource$save(target)


Method clone()

The objects of this class are cloneable with this method.

Usage

Resource$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.