Skip to contents

Efficiently preprocess data

Usage

preprocess_source(
  input,
  output = NULL,
  clean = TRUE,
  cleaningArgs = NULL,
  wordwrap = TRUE,
  wrappingArgs = NULL,
  prependUIDs = TRUE,
  UIDArgs = NULL,
  preventOverwriting = rock::opts$get("preventOverwriting"),
  encoding = rock::opts$get("encoding"),
  rlWarn = rock::opts$get("rlWarn"),
  silent = rock::opts$get("silent")
)

Arguments

input

The source

output

For clean_source and search_and_replace_in_source, if not NULL, this is the name (and path) of the file in which to save the processed source (if it is NULL, the result will be returned visibly). For clean_sources and search_and_replace_in_sources, output is mandatory and is the path to the directory where to store the processed sources. This path will be created with a warning if it does not exist. An exception is if "same" is specified - in that case, every file will be written to the same directory it was read from.

clean

Whether to clean

cleaningArgs

Arguments to use for cleaning

wordwrap

Whether to wordwrap

wrappingArgs

Arguments to use for word wrapping

prependUIDs

Whether to prepend UIDs

UIDArgs

Arguments to use for prepending UIDs

preventOverwriting

Whether to prevent overwriting of output files.

encoding

The encoding of the source(s).

rlWarn

Whether to let readLines() warn, e.g. if files do not end with a newline character.

silent

Whether to suppress the warning about not editing the cleaned source.

Value

The preprocessed source as character vector.

Examples

exampleText <-
  paste0(
    "Lorem ipsum dolor sit amet, consectetur ",
    "adipiscing elit. Nunc non commodo ex, ac ",
    "varius mi. Praesent feugiat nunc eget urna ",
    "euismod lobortis. Sed hendrerit suscipit ",
    "nisl, ac tempus magna porta et. ",
    "Quisque libero massa, tempus vel tristique ",
    "lacinia, tristique in nulla. Nam cursus enim ",
    "dui, non ornare est tempor eu. Vivamus et massa ",
    "consectetur, tristique magna eget, viverra elit."
  );

### Show example text
cat(exampleText);
#> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc non commodo ex, ac varius mi. Praesent feugiat nunc eget urna euismod lobortis. Sed hendrerit suscipit nisl, ac tempus magna porta et. Quisque libero massa, tempus vel tristique lacinia, tristique in nulla. Nam cursus enim dui, non ornare est tempor eu. Vivamus et massa consectetur, tristique magna eget, viverra elit.

### Show preprocessed example text
rock::preprocess_source(
  exampleText
);
#>  [1] "[[uid=7zz4g6d8]] Lorem ipsum dolor sit amet, consectetur"
#>  [2] "[[uid=7zz4g6d9]] adipiscing elit."                       
#>  [3] "[[uid=7zz4g6db]] Nunc non commodo ex, ac varius mi."     
#>  [4] "[[uid=7zz4g6dc]] Praesent feugiat nunc eget urna euismod"
#>  [5] "[[uid=7zz4g6dd]] lobortis."                              
#>  [6] "[[uid=7zz4g6df]] Sed hendrerit suscipit nisl, ac tempus" 
#>  [7] "[[uid=7zz4g6dg]] magna porta et."                        
#>  [8] "[[uid=7zz4g6dh]] Quisque libero massa, tempus vel"       
#>  [9] "[[uid=7zz4g6dj]] tristique lacinia, tristique in nulla." 
#> [10] "[[uid=7zz4g6dk]] Nam cursus enim dui, non ornare est"    
#> [11] "[[uid=7zz4g6dl]] tempor eu."                             
#> [12] "[[uid=7zz4g6dm]] Vivamus et massa consectetur, tristique"
#> [13] "[[uid=7zz4g6dn]] magna eget, viverra elit."