escape_lf: Escape line feeds / newlines

escape_lfR Documentation

Escape line feeds / newlines

Description

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.

See Also

Other string functions: as_chr(), as_comment_str(), as_line_feed_chr(), as_str(), capitalize_first(), dsv_colnames(), enum_str(), fuse_regex(), prettify_nr(), sentenceify(), wrap_chr()

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

# escape newlines and print again
pal::escape_lf(text) |> pal::cat_lines()

salim-b/pal documentation built on Feb. 28, 2025, 6:51 p.m.