ensureVector: Blow up single scalars / objects to vectors / list by...

View source: R/ensureVector.R

ensureVectorR Documentation

Blow up single scalars / objects to vectors / list by replication.

Description

Useful for standard argument conversion where a user can input a single element, but this has to be replicated now n times for a resulting vector or list.

Usage

ensureVector(x, n = 1L, cl = NULL, names = NULL, ensure.list = FALSE)

Arguments

x

[any]
Input element.

n

[integer(1)]
Desired length. Default is 1 (the most common case).

cl

[character*]
Only do the operation if x inherits from this one of these classes, otherwise simply let x pass. Default is NULL which means to always do the operation.

names

[character*]
Names for result. Default is NULL, which means no names.

ensure.list

[logical(1)]
Should x be wrapped in a list in any case? Default is FALSE, i.e., if x is a scalar value, a vector is returned.

Value

Ether a vector or list of length n with replicated x or x unchanged..


BBmisc documentation built on Sept. 29, 2022, 5:12 p.m.

Related to ensureVector in BBmisc...