Learn R Programming

rock (version 0.9.6)

preprocess_source: Efficiently preprocess data

Description

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

Value

The preprocessed source as character vector.

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.

Examples

Run this code
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);

### Show preprocessed example text
rock::preprocess_source(
  exampleText
);

Run the code above in your browser using DataLab