make_list: Make a list of items in x, regardless of x's type

View source: R/utilities.R

make_listR Documentation

Make a list of items in x, regardless of x's type

Description

Repeats x as necessary to make n of them. Does not try to simplify x.

Usage

make_list(x, n, lenx = ifelse(is.vector(x), length(x), 1))

Arguments

x

The object to be duplicated.

n

The number of times to be duplicated.

lenx

The length of item x. Be default, lenx is taken to be length(x),

Details

If x is itself a vector or list, you may want to override the default value for lenx. For example, if x is a list that should be duplicated several times, set lenx = 1.

Value

A list of x duplicated n times

Examples

m <- matrix(c(1:6), nrow=3, dimnames = list(c("r1", "r2", "r3"), c("c2", "c1")))
make_list(m, n = 1)
make_list(m, n = 2)
make_list(m, n = 5)
make_list(list(c(1,2), c(1,2)), n = 4)
m <- matrix(1:4, nrow = 2)
l <- list(m, m+100)
make_list(l, n = 4)
make_list(l, n = 1) # Warning because l is trimmed.
make_list(l, n = 5) # Warning because length(l) (i.e., 2) not evenly divisible by 5
make_list(list(c("r10", "r11"), c("c10", "c11")), n = 2) # Confused by x being a list
make_list(list(c("r10", "r11"), c("c10", "c11")), n = 2, lenx = 1) # Fix by setting lenx = 1

RCLabels documentation built on May 29, 2024, 5:56 a.m.