Copse: Create a copse, a persistent structure for holding R objects...

Description Usage Arguments Details Value Author(s) Examples

Description

This function is a factory for an S3 class ("Copse") that uses an SQLite database to store R objects of class ("Twig") which are related as one or more trees. Each Twig holds a named set of plain-old-data R objects stored in a JSON field, and zero or more user-specified fixed fields, stored as SQLite columns. Twig get/set semantics use $ and $[[]]; i.e. they work like environments. Within an R process, Twigs are copied by reference so that there's really only one version of any Twig. Changes to Twigs are recorded atomically to the SQLite database, so that other processes also have access to them. An atomic get/modify/set operation can be performed on a Twig by using the with() method.

Usage

1
Copse(db, table, ...)

Arguments

db

path to sqlite database with the copse table. This will be created if it doesn't exist.

table

name of sqlite table in the database. This will be created if it doesn't exist in db, with this schema:

   CREATE TABLE <table> (
      id    INTEGER UNIQUE PRIMARY KEY,
      pid   INTEGER REFERENCES <table> (id), -- ID of parent twig, if any
      stump INTEGER REFERENCES <table> (id), -- ID of ultimate ancestor, if any
      ctime FLOAT(53),                       -- twig creation time, unix timestamp
      mtime FLOAT(53),                       -- twig modification time, unix timestamp
      ...
      data  JSON                             -- JSON-serialized object data
   )

where ... represents additional user-specified columns present in all twigs.

The ... columns can be considered the structurally constant part of a Copse, while the data column holds the structurally variable part.

Details

The Copse implements concept of "job" for this package. Job state is stored persistently, and a job should be resumable if the server dies due to power outage, bugs, or fixable errors in the data submitted as a job.

The JSON fields are not indexed, so for fast lookup of simple datatypes, the latter should be provided in the ... at Copse creation time. The JSON fields allow structured datatypes, and allow new records to include data fields not specified when the Copse was created. So if new types of Jobs are implemented as the motusServer package evolves, we don't need to modify the existing jobs database.

The copse manages these functions:

Value

This function creates an object of class "Copse". It has these S3 methods:

Internally a Copse uses these symbols:

Twigs are S3 objects of class "Twig" with these S3 methods:

Internally, a Twig is a numeric vector of class "Twig" with attribute Copse being the Twig's Copse.

Author(s)

John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm

Examples

1
2
3
4
hats = Copse("/home/john/inventory.sqlite", "hats")
b = newTwig(hats, name="bowler", size=22, colour="black")
h = hats[id < 10 || .$size > 20]  ## query can involve id, pid, mtime, ctime, fixed columns, or data variables selected using .$...$...[]...
h[[1]]

jbrzusto/motus-R-package documentation built on May 18, 2019, 7:03 p.m.