Blueprint: The Blueprint (root) super-class

Description Usage Arguments Value Active bindings Methods Author(s) See Also Examples

Description

Blueprint is the root super-class of all R6 classes of package blueprint and provides important low-level mechanisms. All classes of blueprint inherit class Blueprint.

This class is definitely not useful for typical users. You should consider it a virtual class.

Usage

1
2
3
4
5
## Test if an object is a 'Blueprint' object
is_blueprint(x)

## Validate if an object is a proper 'Blueprint' object
valid_blueprint(x)

Arguments

x

any R object.

Value

Active bindings

is_blueprint

A scalar logical always equal to TRUE.

version

A scalar character that registers blueprint's version at the moment the object is created.

Methods

Public methods


Method new()

Create a new Blueprint object.

Usage
Blueprint$new()
Returns

A R6 object of class Blueprint.


Method validate()

Validate a Blueprint object.

Usage
Blueprint$validate()
Returns

The Blueprint object invisibly if the object is valid. Else, an error explaining what is wrong with the object.


Method print()

Print a Blueprint object.

Usage
Blueprint$print()
Details

The object is automatically validated before being printed.

Returns

The Blueprint object invisibly.


Method format()

Format a Blueprint object.

Usage
Blueprint$format()
Returns

A character scalar representing the formatted Blueprint object.


Method get()

Extract a field's value from a Blueprint object.

Usage
Blueprint$get(field = character(), .validate = TRUE)
Arguments
field

A scalar character. The name of a field.

.validate

A scalar logical. Validate the object before calling the method? While this argument is available to the users, it should be ignored, unless you have an alternative way to make sure your underlying object is valid. Since it is a low-level argument, it is not validated, so proceed with care.

Returns

The value corresponding to the chosen field. If it does not exist, NULL is returned. If field is missing, the underlying Blueprint object is returned invisibly.

Examples
## Get a field, here 'version'.
Blueprint$new()$get("version")

## Extract a non-existent field, here 'nope'. NULL is returned.
Blueprint$new()$get("nope")

## Just return the whole object (is a functional style).
## The output is invisible, we must print it to see it.
Blueprint$new()$get()$print()

Method set()

Update a field's value of a Blueprint object.

Usage
Blueprint$set(field = character(), value, .validate = TRUE)
Arguments
field

A scalar character. The name of a field.

value

Any R value. The value to use when updating a field. Its type must match the field's underlying structure.

.validate

A scalar logical. Validate the object before calling the method? While this argument is available to the users, it should be ignored, unless you have an alternative way to make sure your underlying object is valid. Since it is a low-level argument, it is not validated, so proceed with care.

Details

Beware! Class Blueprint has no modifiable fields.

Returns

The Blueprint object invisibly if the object is valid. Else, an error explaining what is wrong with the object.

Examples
## Trying to update a non-public field throws an error!
\dontrun{
Blueprint$new()$set("version", "1.0.0")
}

Author(s)

Jean-Mathieu Potvin (jm@potvin.xyz)

See Also

Other Blueprint classes: Atomic

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## ------------------------------------------------
## Method `Blueprint$get`
## ------------------------------------------------

## Get a field, here 'version'.
Blueprint$new()$get("version")

## Extract a non-existent field, here 'nope'. NULL is returned.
Blueprint$new()$get("nope")

## Just return the whole object (is a functional style).
## The output is invisible, we must print it to see it.
Blueprint$new()$get()$print()

## ------------------------------------------------
## Method `Blueprint$set`
## ------------------------------------------------

## Trying to update a non-public field throws an error!
## Not run: 
Blueprint$new()$set("version", "1.0.0")

## End(Not run)

jeanmathieupotvin/blueprint documentation built on Jan. 17, 2021, 10:54 a.m.