crud: API for CRUD-like operations

Description Usage Arguments Details Value Author(s) Examples

Description

Provides a high-level API for abstracting CRUD operations for arbitrary objects. Currently only create is provided, as this is essential for type management within futile.paradigm. Others will be added as necessary.

Usage

1
2

Arguments

type

The object type to create as a symbol or character

...

Additional arguments to pass to dispatched functions

Details

Adding to 'create' requires a minimal function definition as the harness is provided in the package. Typically a list is returned and the function defines any defaults needed. This is similar to the S4 style but is simpler and not a requirement for using the rest of futile.paradigm.

In general the futile.paradigm avoids strings where syntax is explicit enough that this is possible. By convention types are PascalCased, which makes identifying a type even clearer. For this to work properly, it is essential that class names are not defined as types as defined symbols are assumed to be valid for dereferencing.

Value

'create' returns an object of the requested type.

Author(s)

Brian Lee Yung Rowe

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
create.Car <- function(T, wheels=4, doors=4) list(wheels=wheels, doors=doors)

# This is how you inherit from a type
create.SportsCar <- function(T, doors=2, ...)
  create(Car, doors=doors, ...)

my.car <- create(Car, doors=5)

your.car <- create('SportsCar')

# The type can be passed in via a variable as well
her.class <- 'Car'
her.car <- create(her.class, wheels=3)

my.car %isa% Car
your.car %isa% SportsCar

Example output

Loading required package: futile.options
Loading required package: RUnit
[1] TRUE
[1] TRUE

futile.paradigm documentation built on May 2, 2019, 10:37 a.m.