Skip to contents

Escapes the POSIX-standard newline control character LF (aka \n) which is the standard on Unix/Linux and recent versions of macOS. Set escape_cr = TRUE in order to also escape the carriage return character CR (aka \r) commonly used on Microsoft Windows.

Usage

escape_lf(x, escape_cr = FALSE)

Arguments

x

A character vector.

escape_cr

Whether or not to also escape the carriage return character CR (aka \r). A logical scalar.

Value

A character vector of the same length as x.

Examples

library(magrittr)

# read in and print RStudio add-in registration file as-is
text <-
  fs::path_package(package = "pal",
                   "rstudio", "addins.dcf") |>
  readr::read_file() %T>%
  pal::cat_lines()
#> Name: Build `README.Rmd`
#> Description: Executes `pal::build_readme()`.
#> Binding: build_readme
#> Interactive: false
#> 

# escape newlines and print again
pal::escape_lf(text) |> pal::cat_lines()
#> Name: Build `README.Rmd`\nDescription: Executes `pal::build_readme()`.\nBinding: build_readme\nInteractive: false\n