The goal of the smart.data package is to provide an API that allows for semantic interaction with tabular data as well as governed manipulation of the same. Each smart.data object is an R6 reference class instance which can be symbolically retrieved from memory cache (see cachem_mem) as well as by direct workspace object invocation.

Before using the smart.data reference class for the first time in a user session, smart.start() needs to be invoked in order to create the smart-cache.

Public fields

data

A data.table object holding the current state of the data

name

The label to use to semantically retrieve the smart.data object from cache

id

An auto-generated unique ID for the smart.data object

smart.rules

An environment holding user-generated sets of rules

Active bindings

get.history

Returns the saved history from calls to $capture()

Methods


Method print()

Print Metadata

Usage

smart.data$print()


Method new()

Initialize the class object.

Usage

smart.data$new(x, name = "new_data", ...)

Arguments

x

The input data

name

The name for the smart class when used in smart functions

...

Arguments used to initialize the smart cache (see cache_layered and related). If none are provided, the default is to create a memory cache via cache_mem


Method naming.rule()

$naming.rule provides the prescribed laws for renaming the fields found in self$data. The specified fields found in self$data are renamed when the "law" is enforced.

Usage

smart.data$naming.rule(..., show = FALSE)

Arguments

...

Key-value pairs denoting the naming scheme: new_name = old_name. Items with no key will be used as its own name. dots_list supported.

show

(logical) When TRUE the structure of the rule is printed to console

Returns

Before invisibly returning the class object, a list is saved to self$smart.rules$for_naming containing derived objects used by attribute "law": the expression representing the actions to take when enforced


Method taxonomy.rule()

$taxonomy.rule() sets class object $smart.rules$for_usage which is referenced by method $use(). $taxonomy.rule creates a mapping of fields in $data to labels that can be used to reference them.

Parameter term.map is a data.table object with the following required fields:

Usage

smart.data$taxonomy.rule(..., chatty = FALSE, gui = FALSE)

Arguments

...

(dots_list) These arguments will add, update, or remove taxonomy entries. Arguments should be taxonomy objects created with taxonomy, a length-1 named list consisting of NULL (which removes existing entries), or a named list with child elements structured as follows:

term

(character) The name of the taxonomy term

desc

(character) A description for each term's interpretation or context for usage

fields

(string[]) Optionally provided: contains a vector of field names in $data mapped to the term

chatty

(logical|FALSE) Should additional information be printed to the console?

gui

(logical|FALSE) (ignored)


Method enforce.rules()

$enforce.rules operates on rules saved in $smart.rules and evaluates the quoted "law" on $data. Custom rules can be directly added to class member $smart.rules: they must have an attribute "law" containing a quoted expression referencing object .data and rule. The rule should contain any objects referenced by the quoted expression.

Usage

smart.data$enforce.rules(..., chatty = FALSE)

Arguments

...

(string[]) The names of the rules to enforce

chatty

(logical|FALSE) Should additional execution information be printed to console?

Returns

Invisibly, the class object with member $data modified according to the rules enforced


Method set.private()

$set.private operates on the private class list accessed internally as $private using key-value pairs (i.e. key = value)

Usage

smart.data$set.private(...)

Arguments

...

A named list: existing names in private indicate elements to overwrite

Returns

Invisibly, the class object with member $data modified according to the rules enforced


Method reset()

$reset restores the object $data to the original value and re-initializes rules

Usage

smart.data$reset(safe = TRUE)

Arguments

safe

(logical | TRUE) When TRUE, a confirmation dialog is invoked.

Returns

Invisibly, the class object with member $data modified to the original state


Method use()

$use takes as input taxonomy terms and returns the fields in $data mapped to each term supplied. The idea here is to provide a semantic method for retrieving data.

When no arguments are supplied, the default is to return the fields mapped to existing terms. Using retain = '' returns all values making it equivalent to smart_obj$data

Usage

smart.data$use(
  ...,
  subset = TRUE,
  retain = NULL,
  omit = NULL,
  show = FALSE,
  chatty = FALSE
)

Arguments

...

Taxonomy terms as defined by self$transformation.rule: can be object names or strings

subset

A list of quoted expressions that will row-wise filter the data using data.table syntax

retain, omit

A vector of strings and symbols denoting the fields to retain in the output: pattern-matching is supported

show

(logical|FALSE) Should the rule be shown?

chatty

(logical | TRUE) When TRUE, a confirmation dialog is invoked.

Returns

self$data with columns selected based on the terms supplied


Method cache_mgr()

$cache_mgr adds the current object to the shared "smart" cache space (see cache_layered). The shared cache is layered as 'memory' followed by 'disk.'

Usage

smart.data$cache_mgr(action, chatty = FALSE, ...)

Arguments

action

One of the following (partial matching supported):

  • Add to cache: register, add

  • Remove from cache: unregister, remove

  • Update in cache: update, refresh

chatty

(logical | TRUE) When TRUE, a confirmation dialog is invoked.

...

Additional arguments to use when initializing a cache object


Method capture()

$capture captures the current state of objects in $smart.rules and saves distinct entries as JSON objects.

Usage

smart.data$capture()


Method clone()

The objects of this class are cloneable with this method.

Usage

smart.data$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.