These functions rename one or more codes in one or more sources.

recode_rename(
  input,
  codes,
  filter = TRUE,
  output = NULL,
  filenameRegex = ".*",
  outputPrefix = "",
  outputSuffix = "_rcRenamed",
  decisionLabel = NULL,
  justification = NULL,
  justificationFile = NULL,
  preventOverwriting = rock::opts$get("preventOverwriting"),
  encoding = rock::opts$get("encoding"),
  silent = rock::opts$get("silent")
)

Arguments

input

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().

codes

A named character vector with codes to rename. Each element should be the new code, and the element's name should be the old code (so e.g. codes = c(oldcode1 = 'newcode1', oldcode2 = 'newcode2')).

filter

Optionally, a filter to apply to specify a subset of the source(s) to process (see get_source_filter()).

output

If specified, the recoded source(s) will be written here.

filenameRegex

Only process files matching this regular expression.

outputPrefix, outputSuffix

The prefix and suffix to add to the filenames when writing the processed files to disk, in case multiple sources are passed as input.

decisionLabel

A description of the (recoding) decision that was taken.

justification

The justification for this action.

justificationFile

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().

preventOverwriting

Whether to prevent overwriting existing files when writing the files to output.

encoding

The encoding to use.

silent

Whether to be chatty or quiet.

Value

Invisibly, the changed source(s) or source(s) object.

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");

### Load example source
loadedExample <- rock::load_source(exampleFile);

### Move two codes to a new parent, showing progress
recoded_source <-
  rock::recode_rename(
    loadedExample,
    codes=c(childCode2 = "grownUpCode2",
            grandchildCode2 = "almostChildCode2"),
    silent=FALSE
  );
#> Multiple codes to rename have been specified: starting sequential renaming of 2 codes.
#> 
#> Renaming all occurrences of code 'childCode2' to 'grownUpCode2'.
#> 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 '(\[\[|>)childCode2(\]\]|>)'.
#> --------PRE: ~specimen book. [[parentCode1>childCode2]] [[childCode1]] [[intensity||2]]
#>        POST: ~specimen book. [[parentCode1>grownUpCode2]] [[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]]
#> Renamed 1 code instances of code 'grownUpCode2' to 'childCode2'.
#> 
#> Renaming all occurrences of code 'grandchildCode2' to 'almostChildCode2'.
#> Out of the 132 utterances in the provided source, 132 are selected by the filter, 3 of which contain the code text.
#> Using regular expression '(\[\[|>)grandchildCode2(\]\]|>)'.
#> --------PRE: ~still in their infancy. [[parentCode1>childCode1>grandchildCode2]]
#>        POST: ~still in their infancy. [[parentCode1>childCode1>almostChildCode2]]
#> --------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. [[childCode1>almostChildCode2]]
#> --------PRE: reasonable. The generated Lorem Ipsum is therefore always free from [[grandchildCode2]]
#>        POST: reasonable. The generated Lorem Ipsum is therefore always free from [[almostChildCode2]]
#> Renamed 3 code instances of code 'almostChildCode2' to 'grandchildCode2'.
#>