list_simplify: Simplify a list to an atomic or S3 vector

View source: R/list-simplify.R

list_simplifyR Documentation

Simplify a list to an atomic or S3 vector


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().


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



A list.


These dots are for future extensions and must be empty.


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


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


A vector the same length as x.


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)

purrr documentation built on Aug. 10, 2023, 9:08 a.m.