R: Split a character vector by line breaks

split_lines {xfun} | R Documentation

## 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"))

[Package xfun version 0.27 Index]