Learn R Programming

purrr (version 1.0.2)

list_simplify: Simplify a list to an atomic or S3 vector

Description

Simplification maintains a one-to-one correspondence between the input and output, implying that each element of x must contain a one element vector or a one-row data frame. If you don't want to maintain this correspondence, then you probably want either list_c()/list_rbind() or list_flatten().

Usage

list_simplify(x, ..., strict = TRUE, ptype = NULL)

Value

A vector the same length as x.

Arguments

x

A list.

...

These dots are for future extensions and must be empty.

strict

What should happen if simplification fails? If TRUE, it will error. If FALSE and ptype is not supplied, it will return x unchanged.

ptype

An optional prototype to ensure that the output type is always the same.

Examples

Run this code
list_simplify(list(1, 2, 3))

# Only works when vectors are length one and have compatible types:
try(list_simplify(list(1, 2, 1:3)))
try(list_simplify(list(1, 2, "x")))

# Unless you strict = FALSE, in which case you get the input back:
list_simplify(list(1, 2, 1:3), strict = FALSE)
list_simplify(list(1, 2, "x"), strict = FALSE)

Run the code above in your browser using DataLab