class_container: Container: a class to hold data structures

Description Usage Arguments Details Value Slots The Container class Advantages of using Containers Using the class Extending the Container class See Also

Description

A general, extensible and flexible container holding data and metadata.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
Container(x, ...)

## S4 method for signature 'missing'
Container(x, schema = Schema(), ...)

## S4 method for signature 'character'
Container(x, schema = Schema(), ...)

## S4 method for signature 'data.frame'
Container(x, schema = Schema(), ...)

## S4 method for signature 'data.table'
Container(x, schema = Schema(), ...)

## S4 method for signature 'Schema'
Container(x, ...)

## S4 method for signature 'Container'
show(object)

Arguments

x

conceptually, any R object. Typically, a character, a data.frame, a data.table or a Schema. See details. If missing, an empty object is initialized.

...

further arguments passed to or from other methods:

  • if x is a character, ... is passed to safe_read_csv();

  • if x is a data.frame or an object of class Schema, ... is passed to data.table::as.data.table().

schema

a Schema object. If x is itself an object of class Schema, it should be missing (it is ignored).

object

a Container object.

Details

If a Schema object is passed to Container(), an empty Container is generated. It will have empty columns defined with names and types matching the underlying Schema. Argument schema is ignored for that special case.

Value

The constructor function Container() returns an object of class Container.

The show() method returns NULL invisibly. It is used for its-effect.

Slots

table

a data.table. Its structure must match what slot schema prescribes.

schema

a Schema holding metadata (column names, types and prototypes) on the structure of table.'

The Container class

Class Container is a general container designed to hold any kind of data in an explicit, formal and rigorous way. It can be viewed as a compound structure type which structure is declared through an instance of the Schema class.

Advantages of using Containers

There are four advantages to using the class.

  1. Data manipulation is a seamless hybrid between data.frame and data.table classes.

    • Expression arguments passed to operator [ are viewed as data.table statements.

    • Non-expression arguments are viewed as classical data.frame statements.

  2. A minimal expected table structure is always enforced for increased reliability. This is fundamental in every automated applications expecting specific information.

  3. You don't have to define low-level details and checks. This reduces programming time while adding a negligible cost in compute time.

  4. It is easier to share pre-defined Containers with structures defined by Schema objects.

Using the class

Extending the Container class

For most applications, the Container class will not be specific enough. Users should extend it to a super-class with additional slots by using package methods. Class GeoContainer is a simple example; it adds a sptial component to class Container.

See Also

Other Container: Container-accessors, Container-extractors, Container-methods, Container-validators, is_container()


jeanmathieupotvin/cargo documentation built on Oct. 27, 2020, 5:22 p.m.