buildExpressionFromYaml: Build Expression Based on YAML Markup (generic)

Description Usage Arguments Details YAML syntax Author(s) References See Also Examples

Description

Builds expression(s) based on the YAML markup as identified by getYaml and parsed by parseYaml.

Usage

1

Arguments

yaml

Signature argument. Object containing parsed YAML markup as returned by parseYaml.

where

environment. Environment in which to assign the function in the src field of class ObjectReferenceYaml.S3. Only relevant in case the YAML has been provided via comments instead of an inline string as this involves some additional transformation steps.

...

Further arguments to be passed to subsequent functions/methods.

Details

Expressions that should be executed in order to validate certain aspects can be put into a parsed reference's expr environment at subenvironment "validate" (i.e. {parse-yaml}${id}$expr$validate). That way, at any given time, one could simply execute all expressions in that environment in order to validate if all prerequisites are met (for example "check if the specified reference actually exists and throw an error if it doesn't").

See method buildExpressionFromYaml-ObjectReferenceYamlParsed.S3-method for an example for this

YAML syntax

Note that the YAML statement for specifying object references must be as follows:

object-ref: {id: {id}, where: {where}, as: {id-ref}}

Note that elements where and as are optional and that spaces are required between each syntax component. While the lack of spaces will cause a parsing error in yaml.load, additional spaces do not casue any trouble.

Example for valid YAML statements

See the official http://www.yaml.org/ for more details about YAML

Author(s)

Janko Thyson janko.thyson@rappster.de

References

http://github.com/Rappster/yamlr

See Also

buildExpressionFromYaml-ObjectReferenceYamlParsed.S3-method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Not run: 

## Get //  
yaml <- getYaml(
  from = function() {
  "object-ref: {id: x_1, where: .GlobalEnv, as: ref_1}"
  },
  ctx = YamlContext.ObjectReference.S3()
)

## Parse //
yaml <- parseYaml(yaml = yaml)

## Build //
yaml <- buildExpressionFromYaml(yaml = yaml)

## Two ways of accessing expressions //
## 1) Via 'parsed':
ls(yaml$parsed$x_1$expr)
yaml$parsed$x_1$expr$exists
yaml$parsed$x_1$expr$validate
yaml$parsed$x_1$expr$get_assign

## 2) Via 'expr':
ls(yaml$expr$x_1)
yaml$expr$x_1$exists
yaml$expr$x_1$validate
yaml$expr$x_1$get_assign

## NOTE
## The environment in `expr${id}` corresponds to the environment 
## in `parsed${id}$expr. So expressions are not actually stored redundantly
## as environments implement a "pass-by-referenc" instead of the otherwise
## typical "pass-by-value" paradigm. 
## Environment `expr` simply exists as a shorthand for accessing expressions

## Example of expression execution //
## Validity checks:
suppressWarnings(rm(x_1))
eval(yaml$parsed$x_1$expr$exists)
eval(yaml$parsed$x_1$expr$validate)
x_1 <- 10
eval(yaml$parsed$x_1$expr$exists)
eval(yaml$parsed$x_1$expr$validate)

## The line that contained the YAML markup in 'from' above will be substituted
## by this expression 
eval(yaml$parsed$x_1$expr$get_assign)
ref_1


## End(Not run)

rappster/yamlr documentation built on May 27, 2019, 2:02 a.m.