These function parse one (parse_source) or more (parse_sources) sources and the contained identifiers, sections, and codes.

parse_source(
  text,
  file,
  ignoreOddDelimiters = FALSE,
  postponeDeductiveTreeBuilding = FALSE,
  encoding = rock::opts$get(encoding),
  silent = rock::opts$get(silent)
)

# S3 method for rockParsedSource
print(x, prefix = "### ", ...)

parse_sources(
  path,
  extension = "rock|dct",
  regex = NULL,
  recursive = TRUE,
  ignoreOddDelimiters = FALSE,
  encoding = rock::opts$get(encoding),
  silent = rock::opts$get(silent)
)

# S3 method for rockParsedSources
print(x, prefix = "### ", ...)

# S3 method for rockParsedSources
plot(x, ...)

Arguments

text, 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.

ignoreOddDelimiters

If an odd number of YAML delimiters is encountered, whether this should result in an error (FALSE) or just be silently ignored (TRUE).

postponeDeductiveTreeBuilding

Whether to imediately try to build the deductive tree(s) based on the information in this file (FALSE) or whether to skip that. Skipping this is useful if the full tree information is distributed over multiple files (in which case you should probably call parse_sources instead of parse_source).

encoding

The encoding of the file to read (in file).

silent

Whether to provide (FALSE) or suppress (TRUE) more detailed progress updates.

x

The object to print.

prefix

The prefix to use before the 'headings' of the printed result.

...

Any additional arguments are passed on to the default print method.

path

The path containing the files to read.

extension

The extension of the files to read; files with other extensions will be ignored. Multiple extensions can be separated by a pipe (|).

regex

Instead of specifing an extension, it's also possible to specify a regular expression; only files matching this regular expression are read. If specified, regex takes precedece over extension,

recursive

Whether to also process subdirectories (TRUE) or not (FALSE).

Examples

### Get path to example source examplePath <- system.file("extdata", package="rock"); ### Get a path to one example file exampleFile <- file.path(examplePath, "example-1.rock"); ### Parse single example source parsedExample <- rock::parse_source(exampleFile); ### Show inductive code tree for the codes ### extracted with the regular expression specified with ### the name 'codes': parsedExample$inductiveCodeTrees$codes;
#> levelName #> 1 codes #> 2 ¦--parentCode1 #> 3 ¦ ¦--childCode1 #> 4 ¦ ¦ ¦--grandchildCode1 #> 5 ¦ ¦ ¦--grandchildCode2 #> 6 ¦ ¦ °--grandchildCode3 #> 7 ¦ ¦--childCode2 #> 8 ¦ °--childCode3 #> 9 ¦--parentCode2 #> 10 ¦ ¦--childCode4 #> 11 ¦ ¦ ¦--grandchildCode4 #> 12 ¦ ¦ ¦--grandchildCode5 #> 13 ¦ ¦ °--grandchildCode6 #> 14 ¦ °--childCode5 #> 15 ¦ °--grandchildCode7 #> 16 °--someOtherCode
### If you want `rock` to be chatty, use: parsedExample <- rock::parse_source(exampleFile, silent=FALSE);
#> Read the contents of file 'C:/Users/micro/Documents/R/win-library/4.0/rock/extdata/example-1.rock' (111 lines read). #> Encountered YAML fragments. Parsing them for attributes. #> Read 0 attributes specifications. Continuing with deductive code trees. #> Read 4 deductive codes ('moreChildCodes1', 'moreChildCodes2', 'moreCodes' & 'parentCode1'). #> Read 0 section break codes. #> #> Starting to process the inductive codes and building a code tree. #> Building tree containing all 'true local roots'. #> - Processing 'true local root' 'parentCode1'. #> - Processing 'true local root' 'parentCode2'. #> - Processing 'true local root' 'someOtherCode'. #> #> Processing subtrees of those 'true local roots'. #> #> - Processing subtree consisting of the node sequence 'parentCode1' & 'childCode1'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - Processing node 'childCode1'. #> - This parent node does not yet have a child with the name 'childCode1', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode1', 'childCode1' & 'grandchildCode1'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode1'. #> - This parent node already has a child with the name 'childCode1', so not adding anything at this point. #> - Processing node 'grandchildCode1'. #> - This parent node does not yet have a child with the name 'grandchildCode1', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode1', 'childCode1' & 'grandchildCode2'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode1'. #> - This parent node already has a child with the name 'childCode1', so not adding anything at this point. #> - Processing node 'grandchildCode2'. #> - This parent node does not yet have a child with the name 'grandchildCode2', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode1', 'childCode1' & 'grandchildCode3'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode1'. #> - This parent node already has a child with the name 'childCode1', so not adding anything at this point. #> - Processing node 'grandchildCode3'. #> - This parent node does not yet have a child with the name 'grandchildCode3', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode1' & 'childCode2'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - Processing node 'childCode2'. #> - This parent node does not yet have a child with the name 'childCode2', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode1' & 'childCode3'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - Processing node 'childCode3'. #> - This parent node does not yet have a child with the name 'childCode3', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode2' & 'childCode4'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - Processing node 'childCode4'. #> - This parent node does not yet have a child with the name 'childCode4', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode2', 'childCode4' & 'grandchildCode4'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode4'. #> - This parent node already has a child with the name 'childCode4', so not adding anything at this point. #> - Processing node 'grandchildCode4'. #> - This parent node does not yet have a child with the name 'grandchildCode4', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode2', 'childCode4' & 'grandchildCode5'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode4'. #> - This parent node already has a child with the name 'childCode4', so not adding anything at this point. #> - Processing node 'grandchildCode5'. #> - This parent node does not yet have a child with the name 'grandchildCode5', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode2', 'childCode4' & 'grandchildCode6'. #> - This subtree doesn't only consist of the parent/root code, but contains 2 child(ren). Processing child(ren). #> - Processing node 'childCode4'. #> - This parent node already has a child with the name 'childCode4', so not adding anything at this point. #> - Processing node 'grandchildCode6'. #> - This parent node does not yet have a child with the name 'grandchildCode6', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'parentCode2' & 'childCode5'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - Processing node 'childCode5'. #> - This parent node does not yet have a child with the name 'childCode5', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'someOtherCode'. #> - This 'subtree' only consists of the parent/root code, so no further processing required. #> #> Processing subtrees of 'local roots that are branches', i.e. single codes that are descendants of other codes (without the full path to the root being specified in the code), or subtrees where the local root is in fact a descendant. #> #> - Processing subtree consisting of the node sequence 'childCode1'. #> - This 'subtree' only consists of the parent/root code, so no further processing required. #> #> - Processing subtree consisting of the node sequence 'childCode1' & 'grandchildCode2'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - This parent node already has a child with the name 'grandchildCode2', so not adding anything at this point. #> #> - Processing subtree consisting of the node sequence 'childCode5' & 'grandchildCode7'. #> - This subtree doesn't only consist of the parent/root code, but contains 1 child(ren). Processing child(ren). #> - This parent node does not yet have a child with the name 'grandchildCode7', so adding it to that parent node. #> #> - Processing subtree consisting of the node sequence 'grandchildCode2'. #> - This 'subtree' only consists of the parent/root code, so no further processing required. #> #> Done processing the inductive code tree. #>
### Parse all example sources in that directory parsedExamples <- rock::parse_sources(examplePath); ### Show combined inductive code tree for the codes ### extracted with the regular expression specified with ### the name 'codes': parsedExamples$inductiveCodeTrees$codes;
#> levelName #> 1 codes #> 2 ¦--parentCode1 #> 3 ¦ ¦--childCode1 #> 4 ¦ ¦ ¦--grandchildCode1 #> 5 ¦ ¦ ¦--grandchildCode2 #> 6 ¦ ¦ °--grandchildCode3 #> 7 ¦ ¦--childCode2 #> 8 ¦ °--childCode3 #> 9 ¦--parentCode2 #> 10 ¦ ¦--childCode4 #> 11 ¦ ¦ ¦--grandchildCode4 #> 12 ¦ ¦ ¦--grandchildCode5 #> 13 ¦ ¦ °--grandchildCode6 #> 14 ¦ °--childCode5 #> 15 ¦ °--grandchildCode7 #> 16 ¦--someOtherCode #> 17 ¦--att_ins_eval #> 18 ¦--chairs #> 19 ¦--inductFather #> 20 ¦ ¦--inducChild3 #> 21 ¦ ¦--inducChild4 #> 22 ¦ °--inducChild5 #> 23 ¦--inductMother #> 24 ¦ ¦--inducChild1 #> 25 ¦ °--inducChild2 #> 26 ¦--internet #> 27 ¦--oaken_chests #> 28 ¦--people #> 29 ¦--tables #> 30 ¦--Topic1 #> 31 ¦--Topic2 #> 32 ¦--bla #> 33 ¦ ¦--subbla #> 34 ¦ ¦ ¦--bla2 #> 35 ¦ ¦ °--bla3 #> 36 ¦ °--subbla2 #> 37 ¦--flups #> 38 ¦--pets #> 39 ¦ °--cats #> 40 ¦ °--siamese #> 41 ¦--property #> 42 ¦ °--hairy #> 43 °--relationships #> 44 °--love