Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ensureVector

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

Miscellaneous Helper Functions for B. Bischl

v1.11
BSD_2_clause + file LICENSE
Authors
Bernd Bischl [aut, cre], Michel Lang [aut], Jakob Bossek [aut], Daniel Horn [aut], Jakob Richter [aut], Dirk Surmann [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.