R/code_source.R
, R/code_sources.R
coding_sources.Rd
These functions add codes to one or more
sources that were read with one of the
loading_sources
functions.
code_source(
input,
codes,
indices = NULL,
output = NULL,
decisionLabel = NULL,
justification = NULL,
justificationFile = NULL,
preventOverwriting = rock::opts$get("preventOverwriting"),
rlWarn = rock::opts$get(rlWarn),
encoding = rock::opts$get("encoding"),
silent = rock::opts$get("silent")
)
code_sources(
input,
codes,
output = NULL,
indices = NULL,
outputPrefix = "",
outputSuffix = "_coded",
decisionLabel = NULL,
justification = NULL,
justificationFile = NULL,
recursive = TRUE,
filenameRegex = ".*",
preventOverwriting = rock::opts$get("preventOverwriting"),
encoding = rock::opts$get("encoding"),
silent = rock::opts$get("silent")
)
The source, or list of sources, as
produced by one of the loading_sources
functions.
A named character vector, where each element is the code to be added to the matching utterance, and the corresponding name is either an utterance identifier (in which case the utterance with that identifier will be coded with that code), a code (in which case all utterances with that code will be coded with the new code as well), a digit (in which case the utterance at that line number in the source will be coded with that code), or a regular expression, in which case all utterances matching that regular expression will be coded with that source. If specifying an utterance ID or code, make sure that the code delimiters are included (normally, two square brackets).
If input
is a source as loaded by
loading_sources
, indices
can be used to pass a logical
vector of the same length as input
that indicates to which utterance the code in codes
should be
applied. Note that if indices
is provided, only the first
element of codes
is used, and its name is ignored.
If specified, the coded source will be written here.
A description of the (coding) decision that was taken.
The justification for this action.
If specified, the justification is appended to
this file. If not, it is saved to the justifier::workspace()
. This can
then be saved or displayed at the end of the R Markdown file or R script
using justifier::save_workspace()
.
Whether to prevent overwriting existing files.
Whether to let readLines()
warn, e.g. if files do not end
with a newline character.
The encoding to use.
Whether to be chatty or quiet.
A prefix and/or suffix to prepend and/or append to the filenames to distinguish them from the input filenames.
Whether to also read files from all subdirectories
of the input
directory
Only input files matching this patterns will be read.
Invisibly, the coded source object.
### 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]);
#> The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for
### 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]);
#> The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for [[ipsum]] [[timeRef]]
### Also add code "foo" to utterances with code 'ipsum'
moreCodedExample <- code_source(codedExample,
c("[[ipsum]]" = "foo"));
### Show line 71
cat(moreCodedExample[71]);
#> The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for [[ipsum]] [[timeRef]] [[foo]]
### Use the 'indices' argument to add the code 'bar' to
### line 71
overCodedExample <- code_source(moreCodedExample,
"bar",
indices=71);
cat(overCodedExample[71]);
#> The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for [[ipsum]] [[timeRef]] [[foo]]