v2lv {str2str}R Documentation

(Atomic) Vector to List of (Atomic) Vectors

Description

v2lv converts a (atomic) vector to a list of atomic vectors. The default is conversion to a list vector where each element of the list has only one element. The n.break argument allows for the input vector to be broken up into larger sections with each section being a list element in the return object.

Usage

v2lv(v, use.names = TRUE, n.break = 1L, warn.break = TRUE, check = TRUE)

Arguments

v

(atomic) vector.

use.names

logical vector of length 1 specifying whether the names from v should be retained in the return object.

n.break

integer vector of length 1 specifying how v should be broken up. Every n.break elements while seq_along v, a new element of the list is created and subsequent elements of v are stored there. If n.break is not a multiple of length(v), then NAs are appended to the end of v to ensure that each list element has (atomic) vectors of the same length. Note, the default is 1L resulting in a list vector.

warn.break

logical vector of length one specifying whether a warning should be printed if length(v) / n.break is not a whole number, which would then result in NAs being appended to the end of the vector before converting to a list.

check

logical vector of length 1 specifying whether to check the structure of the input arguments. For example, check whether v is an atomic vector. This argument is available to allow flexibility in whether the user values informative error messages (TRUE) vs. computational efficiency (FALSE).

Details

Future versions of this function plan to allow for use similar to the utils::relist function to allow reconstruction after flattening a matrix-like object to a single vector.

Value

list of (atomic) vectors that are the elements of v broken up according to n.break. The list only has names if v has names and n.break = 1L.

Examples

vec <- setNames(object = mtcars[[1]], nm = row.names(mtcars))
v2lv(vec)
v2lv(vec, use.names = FALSE)
vec <- unlist(mtcars)
v2lv(vec, n.break = 32) # n.break > 1L and multiple of length(v)
v2lv(vec, n.break = 30) # n.break > 1L and NOT multiple of length(v)

[Package str2str version 1.0.0 Index]