This function wordwraps a source.
Usage
wordwrap_source(
input,
output = NULL,
length = 40,
removeNewlines = FALSE,
removeTrailingNewlines = TRUE,
rlWarn = rock::opts$get(rlWarn),
preventOverwriting = rock::opts$get("preventOverwriting"),
encoding = rock::opts$get(encoding),
silent = rock::opts$get(silent),
utteranceMarker = rock::opts$get("utteranceMarker")
)
Arguments
- input
For
clean_source
andsearch_and_replace_in_source
, either a character vector containing the text of the relevant source or a path to a file that contains the source text; forclean_sources
andsearch_and_replace_in_sources
, a path to a directory that contains the sources to clean.- output
For
clean_source
andsearch_and_replace_in_source
, if notNULL
, this is the name (and path) of the file in which to save the processed source (if it isNULL
, the result will be returned visibly). Forclean_sources
andsearch_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.- length
At how many characters to word wrap.
- removeNewlines
Whether to remove all newline characters from the source before starting to clean them. Be careful: if the source contains YAML fragments, these will also be affected by this, and will probably become invalid!
- removeTrailingNewlines
Whether to remove trailing newline characters (i.e. at the end of a character value in a character vector);
- rlWarn
Whether to let
readLines()
warn, e.g. if files do not end with a newline character.- preventOverwriting
Whether to prevent overwriting of output files.
- encoding
The encoding of the source(s).
- silent
Whether to suppress the warning about not editing the cleaned source.
- utteranceMarker
The character(s) between utterances (i.e. marking where one utterance ends and the next one starts). By default, this is a line break, and only change this if you know what you are doing.
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
cat(
paste0(
rock::wordwrap_source(
exampleText
),
collapse = "\n"
)
);
#> 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.