Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

split_lines

Split a character vector by line breaks


Description

Call unlist(strsplit(x, '\n')) on the character vector x and make sure it works in a few edge cases: split_lines('') returns '' instead of character(0) (which is the returned value of strsplit('', '\n')); split_lines('a\n') returns c('a', '') instead of c('a') (which is the returned value of strsplit('a\n', '\n').

Usage

split_lines(x)

Arguments

x

A character vector.

Value

All elements of the character vector are split by '\n' into lines.

Examples

xfun::split_lines(c("a", "b\nc"))

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.