These functions move a code to a different parent (and therefore, ancestry) in one or more sources.
recode_move(
input,
codes,
newAncestry,
filter = TRUE,
output = NULL,
filenameRegex = ".*",
outputPrefix = "",
outputSuffix = "_rcMoved",
decisionLabel = NULL,
justification = NULL,
justificationFile = NULL,
preventOverwriting = rock::opts$get("preventOverwriting"),
encoding = rock::opts$get("encoding"),
silent = rock::opts$get("silent")
)
One of 1) a character string specifying the path to a file
with a source; 2) an object with a loaded source as produced by a call
to load_source()
; 3) a character string specifying the path to a directory
containing one or more sources; 4) or an object with a list of loaded
sources as produced by a call to load_sources()
.
A character vector with codes to move.
The new parent code, optionally including the partial or full ancestry (i.e. the path of parent codes all the way up to the root).
Optionally, a filter to apply to specify a subset of the
source(s) to process (see get_source_filter()
).
If specified, the recoded source(s) will be written here.
Only process files matching this regular expression.
The prefix and suffix to add to the filenames when writing the processed files to disk, in case multiple sources are passed as input.
A description of the (recoding) 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
when writing the files to output
.
The encoding to use.
Whether to be chatty or quiet.
Invisibly, the changed source(s) or source(s) 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");
### Load example source
loadedExample <- rock::load_source(exampleFile);
### Move two codes to a new parent, showing progress
recoded_source <-
rock::recode_move(
loadedExample,
codes=c("childCode2", "childCode1"),
newAncestry = "parentCode2",
silent=FALSE
);
#> Multiple codes to move have been specified: starting sequential moving of 2 codes.
#> Moving all occurrences of code 'childCode2' to new ancestry 'parentCode2>'.
#> Out of the 132 utterances in the provided source, 132 are selected by the filter, 4 of which contain the code text.
#> Using regular expression '(\s?\[\[)([a-zA-Z0-9_>]*>)?(childCode2>?[a-zA-Z0-9_>]*\]\])'.
#> --------PRE: ~specimen book. [[parentCode1>childCode2]] [[childCode1]] [[intensity||2]]
#> POST: ~specimen book. [[parentCode2>childCode2]] [[childCode1]] [[intensity||2]]
#> --UNCHANGED: ~still in their infancy. [[parentCode1>childCode1>grandchildCode2]]
#> --UNCHANGED: accompanied by English versions from the 1914 translation by H. Rackham. [[childCode1>grandchildCode2]]
#> --UNCHANGED: reasonable. The generated Lorem Ipsum is therefore always free from [[grandchildCode2]]
#> Moved 1 code instances for code 'childCode2'.
#>
#> Moving all occurrences of code 'childCode1' to new ancestry 'parentCode2>'.
#> Out of the 132 utterances in the provided source, 132 are selected by the filter, 6 of which contain the code text.
#> Using regular expression '(\s?\[\[)([a-zA-Z0-9_>]*>)?(childCode1>?[a-zA-Z0-9_>]*\]\])'.
#> --------PRE: Lorem Ipsum is simply dummy text of the printing and typesetting industry. [[parentCode1>childCode1]]
#> POST: Lorem Ipsum is simply dummy text of the printing and typesetting industry. [[parentCode2>childCode1]]
#> --------PRE: ~specimen book. [[parentCode2>childCode2]] [[childCode1]] [[intensity||2]]
#> POST: ~specimen book. [[parentCode2>childCode2]] [[parentCode2>childCode1]] [[intensity||2]]
#> --------PRE: using 'Content here, content here', making it look like readable English. [[parentCode1>childCode1>grandchildCode1]]
#> POST: using 'Content here, content here', making it look like readable English. [[parentCode2>childCode1>grandchildCode1]]
#> --------PRE: ~still in their infancy. [[parentCode1>childCode1>grandchildCode2]]
#> POST: ~still in their infancy. [[parentCode2>childCode1>grandchildCode2]]
#> --------PRE: by accident, sometimes on purpose (injected humour and the like). [[parentCode1>childCode1>grandchildCode3]]
#> POST: by accident, sometimes on purpose (injected humour and the like). [[parentCode2>childCode1>grandchildCode3]]
#> --------PRE: accompanied by English versions from the 1914 translation by H. Rackham. [[childCode1>grandchildCode2]]
#> POST: accompanied by English versions from the 1914 translation by H. Rackham. [[parentCode2>childCode1>grandchildCode2]]
#> Moved 6 code instances for code 'childCode1'.
#>