Learn R Programming

super (version 0.1.1)

trim: Trim a character vector

Description

Almost identical to glue::trim() save a slight difference in error handling for non-character input. This function trims a character vector according to the trimming rules used by glue. These follow similar rules to Python Docstrings, with the following features:

  • Leading and trailing whitespace from the first and last lines is removed.

  • A uniform amount of indentation is stripped from the second line on, equal to the minimum indentation of all non-blank lines after the first.

  • Lines can be continued across newlines by using \\.

Usage

trim(x)

Value

A character vector.

Arguments

x

[character].

See Also

Examples

Run this code
cat(trim("
    A formatted string
    Can have multiple lines
      with additional indentation preserved
    "))

cat(trim("
  \ntrailing or leading newlines can be added explicitly\n
  "))

cat(trim("
    A formatted string \\
    can also be on a \\
    single line
    "))

Run the code above in your browser using DataLab