Description Usage Arguments Details YAML syntax Author(s) References See Also Examples
Builds expression(s) based on the YAML markup as identified by
getYaml
and parsed by parseYaml
.
1 | buildExpressionFromYaml(yaml, where = parent.frame(), ...)
|
yaml |
Signature argument.
Object containing parsed YAML markup as returned by
|
where |
|
... |
Further arguments to be passed to subsequent functions/methods. |
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
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
object-ref: {id: x_1, where: .GlobalEnv, as: ref_1}
object-ref: {id: x_1, where: .GlobalEnv}
object-ref: {id: x_1}
object-ref: { id: x_1, where : .GlobalEnv, as: ref_1 }
See the official http://www.yaml.org/ for more details about YAML
Janko Thyson janko.thyson@rappster.de
http://github.com/Rappster/yamlr
buildExpressionFromYaml-ObjectReferenceYamlParsed.S3-method
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.