read_text_lines: Split and trim new-line-delimited string of values

Description Usage Arguments Value Examples

View source: R/utils-text.R

Description

THis function mimics some of the nice thing glue does with trimming. The option to keep internal blanks was added for puzzle 2020:04.

Usage

1
read_text_lines(x, drop_empty = "all")

Arguments

x

a string with values separated by newlines

drop_empty

whether to remove empty items ("") from the results. Defaults to "all". Other options are "head/tail" (drops blanks from start and end) and "none".

Value

a character vector of values split at newlines and with leading and trailing spaces removed.

Examples

1
2
3
4
5
read_text_lines("a\n  b  \nc    ")

read_text_lines("\n\na\n  b  \n\nc    \n\n", drop_empty = "none")
read_text_lines("\n\na\n  b  \n\nc    \n\n", drop_empty = "all")
read_text_lines("\n\na\n  b  \n\nc    \n\n", drop_empty = "head/tail")

tjmahr/adventofcode20 documentation built on Dec. 31, 2020, 8:39 a.m.