### 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
loadedExample <- rock::load_source(exampleFile);
### Show line 71
cat(loadedExample[71]);
### Specify the rules to code all utterances
### containing "Ipsum" with the code 'ipsum' and
### all utterances containing the code
codeSpecs <-
c("(?i)ipsum" = "ipsum",
"BC|AD|\\d\\d\\d\\ds" = "timeRef");
### Apply rules
codedExample <- code_source(loadedExample,
codeSpecs);
### Show line 71
cat(codedExample[71]);
### Also add code "foo" to utterances with code 'ipsum'
moreCodedExample <- code_source(codedExample,
c("[[ipsum]]" = "foo"));
### Show line 71
cat(moreCodedExample[71]);
### Use the 'indices' argument to add the code 'bar' to
### line 71
overCodedExample <- code_source(moreCodedExample,
"bar",
indices=71);
cat(overCodedExample[71]);
Run the code above in your browser using DataLab