load_and_simplify {yum} | R Documentation |
Load YAML fragments in one or multiple files and simplify them
Description
These function extracts all YAML fragments from a file or text (load_and_simplify
)
or from all files in a directory (load_and_simplify_dir
) and loads them
by calling load_yaml_fragments()
, and then calls simplify_by_flattening()
,
on the result, returning the resulting list.
Usage
load_and_simplify(
text,
file,
yamlFragments = NULL,
select = ".*",
simplify = ".*",
delimiterRegEx = "^---$",
ignoreOddDelimiters = FALSE,
encoding = "UTF-8",
silent = TRUE
)
load_and_simplify_dir(
path,
recursive = TRUE,
fileRegexes = c("^[^\\.]+.*$"),
select = ".*",
simplify = ".*",
delimiterRegEx = "^---$",
ignoreOddDelimiters = FALSE,
encoding = "UTF-8",
silent = TRUE
)
Arguments
text |
As text or file , you can specify a file to read with
encoding encoding , which will then be read using base::readLines() . If the
argument is named text , whether it is the path to an existing file is checked
first, and if it is, that file is read. If the argument is named file , and it
does not point to an existing file, an error is produced (useful if calling
from other functions). A text should be a character vector where every
element is a line of the original source (like provided by base::readLines() );
although if a character vector of one element and including at least one
newline character (\\n ) is provided as text , it is split at the newline
characters using base::strsplit() . Basically, this behavior means that the
first argument can be either a character vector or the path to a file; and if
you're specifying a file and you want to be certain that an error is thrown if
it doesn't exist, make sure to name it file .
|
file |
As text or file , you can specify a file to read with
encoding encoding , which will then be read using base::readLines() . If the
argument is named text , whether it is the path to an existing file is checked
first, and if it is, that file is read. If the argument is named file , and it
does not point to an existing file, an error is produced (useful if calling
from other functions). A text should be a character vector where every
element is a line of the original source (like provided by base::readLines() );
although if a character vector of one element and including at least one
newline character (\\n ) is provided as text , it is split at the newline
characters using base::strsplit() . Basically, this behavior means that the
first argument can be either a character vector or the path to a file; and if
you're specifying a file and you want to be certain that an error is thrown if
it doesn't exist, make sure to name it file .
|
yamlFragments |
A character vector of class yamlFragment where
every element corresponds to one line of the YAML fragments, or a list
of multiple such character vectors (of class yamlFragments ). Specify
either yamlFragments (which, if specified, takes precedence over file
and text ), file , or text (file takes precedence over text ).
|
select |
A vector of regular expressions specifying object names
to retain. The default (.* ) matches everything, so by default, all
objects are retained.
|
simplify |
A regular expression specifying which elements to
simplify (default is everything)
|
delimiterRegEx |
The regular expression used to locate YAML
fragments.
|
ignoreOddDelimiters |
Whether to throw an error (FALSE) or
delete the last delimiter (TRUE) if an odd number of delimiters is
encountered.
|
encoding |
The encoding to use when calling readLines() . Set to
NULL to let readLines() guess.
|
silent |
Whether to be silent (TRUE ) or informative (FALSE ).
|
path |
The path containing the files.
|
recursive |
Whether to also process subdirectories (TRUE )
or not (FALSE ).
|
fileRegexes |
A vector of regular expressions to match the files
against: only files matching one or more regular expressions in this
vector are processed. The default regex (^[^\.]+.*$ ) matches all
files except those that start with a period (. ).
|
Value
A list of objects, where each object corresponds to one
item specified in the read YAML fragment(s) from the source file
or text. If the convention of the rock
, dct
and justifier
packages is followed, each object in this list contains one or
more named objects (lists), where the name indicates the type
of information contained. Each of those objects (lists) then
contains one or more objects of that type, such as metadata or
codes for rock
, a decentralized construct taxonomy element
for dct
, and a justification, decision, assertion, or source
for justifier
.
Examples
yum::load_and_simplify(text="
---
firstObject:
id: firstFragment
---
Outside of YAML
---
otherObjectType:
-
id: secondFragment
parentId: firstFragment
-
id: thirdFragment
parentId: firstFragment
---
Also outside of YAML");
[Package
yum version 0.1.0
Index]