Collect all coded utterances and optionally add some context (utterances before and utterances after) to create ann overview of all coded fragments per code.

collect_coded_fragments(
  x,
  codes = ".*",
  context = 0,
  attributes = NULL,
  heading = NULL,
  headingLevel = 3,
  add_html_tags = TRUE,
  cleanUtterances = FALSE,
  output = NULL,
  template = "default",
  rawResult = FALSE,
  includeBootstrap = rock::opts$get("includeBootstrap"),
  preventOverwriting = rock::opts$get(preventOverwriting),
  silent = rock::opts$get(silent)
)

Arguments

x

The parsed source(s) as provided by rock::parse_source or rock::parse_sources.

codes

The regular expression that matches the codes to include

context

How many utterances before and after the target utterances to include in the fragments.

attributes

To only select coded utterances matching one or more values for one or more attributes, pass a list where every element's name is a valid (i.e. occurring) attribute name, and every element is a character value with a regular expression specifying all values for that attribute to select.

heading

Optionally, a title to include in the output. The title will be prefixed with headingLevel hashes (#), and the codes with headingLevel+1 hashes. If NULL (the default), a heading will be generated that includes the collected codes if those are five or less. If a character value is specified, that will be used. To omit a heading, set to anything that is not NULL or a character vector (e.g. FALSE). If no heading is used, the code prefix will be headingLevel hashes, instead of headingLevel+1 hashes.

headingLevel

The number of hashes to insert before the headings.

add_html_tags

Whether to add HTML tags to the result.

cleanUtterances

Whether to use the clean or the raw utterances when constructing the fragments (the raw versions contain all codes). Note that this should be set to FALSE to have add_html_tags be of the most use.

output

Here, a path and filename can be provided where the result will be written. If provided, the result will be returned invisibly.

template

The template to load; either the name of one of the ROCK templates (currently, only 'default' is available), or the path and filename of a CSS file.

rawResult

Whether to return the raw result, a list of the fragments, or one character value in markdown format.

preventOverwriting

Whether to prevent overwriting of output files.

silent

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

Value

Either a list of character vectors, or a single character value.

Details

By default, the output is optimized for inclusion in an R Markdown document. To optimize output for the R console or a plain text file, without any HTML codes, set add_html_tags to FALSE, and potentially set cleanUtterances to only return the utterances, without the codes.

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 organised coded fragments in Markdown cat(collect_coded_fragments(parsedExample));
#> #> <style #> > #> #> .code { #> border-radius: .25em; #> box-sizing: border-box; #> margin-left: 10px; #> padding: 2px; #> } #> #> .identifier { #> border-radius: .25em; #> box-sizing: border-box; #> margin-left: 10px; #> padding: 2px; #> } #> #> .sectionBreak { #> border-radius: .25em; #> box-sizing: border-box; #> display: block; #> } #> #> .uid { #> border-radius: 0; #> box-sizing: border-box; #> } #> #> .utterance { #> display: block; #> } #> #> .code { #> background-color: #f4d142; #> } #> #> .identifier { #> background-color: #aaaaff; #> } #> #> .sectionBreak { #> background-color: #eeeeff; #> } #> #> .uid { #> background-color: #eeeeee; #> color: #bbbbbb; #> } #> #> .utterance { #> border-top: 1px dotted black; #> border-bottom: 1px dotted black; #> } #> #> .utterance + .utterance { #> margin-top: -1px; #> } #> </style> #> #> #> ### Collected coded fragments with 0 lines of context #> #> #### childCode1 *(path: childCode1)* #> #> ----- #> #> <div class="utterance">Lorem Ipsum is simply dummy text of the printing and typesetting industry. <span class="code codes">[[parentCode1&gt;childCode1]]</span></div> #> #> #> ----- #> #> <div class="utterance">specimen book. <span class="code codes">[[parentCode1&gt;childCode2]]</span> <span class="code codes">[[childCode1]]</span></div> #> #> #> ----- #> #> #> #### childCode2 *(path: childCode1>grandchildCode2)* #> #> ----- #> #> <div class="utterance">specimen book. <span class="code codes">[[parentCode1&gt;childCode2]]</span> <span class="code codes">[[childCode1]]</span></div> #> #> #> ----- #> #> #> #### childCode3 *(path: childCode5>grandchildCode7)* #> #> ----- #> #> <div class="utterance">electronic typesetting, remaining essentially unchanged. <span class="code codes">[[parentCode1&gt;childCode3]]</span> <span class="code codes">[[someOtherCode]]</span></div> #> #> #> ----- #> #> #> #### childCode4 *(path: grandchildCode2)* #> #> ----- #> #> <div class="utterance">including versions of Lorem Ipsum. <span class="code codes">[[parentCode2&gt;childCode4]]</span></div> #> #> #> ----- #> #> #> #### childCode5 *(path: parentCode1>childCode1)* #> #> ----- #> #> <div class="utterance">content of a page when looking at its layout. <span class="code codes">[[parentCode2&gt;childCode5]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode1 *(path: parentCode1>childCode1>grandchildCode1)* #> #> ----- #> #> <div class="utterance">using 'Content here, content here', making it look like readable English. <span class="code codes">[[parentCode1&gt;childCode1&gt;grandchildCode1]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode2 *(path: parentCode1>childCode1>grandchildCode2)* #> #> ----- #> #> <div class="utterance">still in their infancy. <span class="code codes">[[parentCode1&gt;childCode1&gt;grandchildCode2]]</span></div> #> #> #> ----- #> #> <div class="utterance">accompanied by English versions from the 1914 translation by H. Rackham. <span class="code codes">[[childCode1&gt;grandchildCode2]]</span></div> #> #> #> ----- #> #> <div class="utterance">reasonable. The generated Lorem Ipsum is therefore always free from <span class="code codes">[[grandchildCode2]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode3 *(path: parentCode1>childCode1>grandchildCode3)* #> #> ----- #> #> <div class="utterance">by accident, sometimes on purpose (injected humour and the like). <span class="code codes">[[parentCode1&gt;childCode1&gt;grandchildCode3]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode4 *(path: parentCode1>childCode2)* #> #> ----- #> #> <div class="utterance">Where does it come from? <span class="code codes">[[parentCode2&gt;childCode4&gt;grandchildCode4]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode5 *(path: parentCode1>childCode3)* #> #> ----- #> #> <div class="utterance">old. <span class="code codes">[[parentCode2&gt;childCode4&gt;grandchildCode5]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode6 *(path: parentCode2>childCode4)* #> #> ----- #> #> <div class="utterance">discovered the undoubtable source. <span class="code codes">[[parentCode2&gt;childCode4&gt;grandchildCode6]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode7 *(path: parentCode2>childCode4>grandchildCode4)* #> #> ----- #> #> <div class="utterance">repetition, injected humour, or non-characteristic words etc. <span class="code codes">[[childCode5&gt;grandchildCode7]]</span></div> #> #> #> ----- #> #> #> #### someOtherCode *(path: parentCode2>childCode4>grandchildCode5)* #> #> ----- #> #> <div class="utterance">electronic typesetting, remaining essentially unchanged. <span class="code codes">[[parentCode1&gt;childCode3]]</span> <span class="code codes">[[someOtherCode]]</span></div> #> #> #> ----- #>
### Only for the codes containing 'Code2' cat(collect_coded_fragments(parsedExample, 'Code2'));
#> #> <style #> > #> #> .code { #> border-radius: .25em; #> box-sizing: border-box; #> margin-left: 10px; #> padding: 2px; #> } #> #> .identifier { #> border-radius: .25em; #> box-sizing: border-box; #> margin-left: 10px; #> padding: 2px; #> } #> #> .sectionBreak { #> border-radius: .25em; #> box-sizing: border-box; #> display: block; #> } #> #> .uid { #> border-radius: 0; #> box-sizing: border-box; #> } #> #> .utterance { #> display: block; #> } #> #> .code { #> background-color: #f4d142; #> } #> #> .identifier { #> background-color: #aaaaff; #> } #> #> .sectionBreak { #> background-color: #eeeeff; #> } #> #> .uid { #> background-color: #eeeeee; #> color: #bbbbbb; #> } #> #> .utterance { #> border-top: 1px dotted black; #> border-bottom: 1px dotted black; #> } #> #> .utterance + .utterance { #> margin-top: -1px; #> } #> </style> #> #> #> ### Collected coded fragments for codes 'childCode2' & 'grandchildCode2' with 0 lines of context #> #> #### childCode2 *(path: childCode1>grandchildCode2)* #> #> ----- #> #> <div class="utterance">specimen book. <span class="code codes">[[parentCode1&gt;childCode2]]</span> <span class="code codes">[[childCode1]]</span></div> #> #> #> ----- #> #> #> #### grandchildCode2 *(path: parentCode1>childCode1>grandchildCode2)* #> #> ----- #> #> <div class="utterance">still in their infancy. <span class="code codes">[[parentCode1&gt;childCode1&gt;grandchildCode2]]</span></div> #> #> #> ----- #> #> <div class="utterance">accompanied by English versions from the 1914 translation by H. Rackham. <span class="code codes">[[childCode1&gt;grandchildCode2]]</span></div> #> #> #> ----- #> #> <div class="utterance">reasonable. The generated Lorem Ipsum is therefore always free from <span class="code codes">[[grandchildCode2]]</span></div> #> #> #> ----- #>