i2index: Input parameter check for subsetting operations

View source: R/i2index.R

i2indexR Documentation

Input parameter check for subsetting operations

Description

i2index is a simple helper function to be used in subsetting functions. It checks and converts the parameter i, which can be of type integer, logical or character to integer vector that can be used as index for subsetting.

Usage

i2index(i, length = length(i), names = NULL)

Arguments

i

character logical or integer used in ⁠[i]⁠ for subsetting.

length

integer representing the length of the object to be subsetted.

names

character with the names (rownames or similar) of the object. This is only required if i is of type character.

Value

integer with the indices

Author(s)

Johannes Rainer

Examples


## With `i` being an `integer`
i2index(c(4, 1, 3), length = 10)

## With `i` being a `logical`
i2index(c(TRUE, FALSE, FALSE, TRUE, FALSE), length = 5)

## With `i` being a `character`
i2index(c("b", "a", "d"), length = 5, names = c("a", "b", "c", "d", "e"))

rformassspectrometry/MsCoreUtils documentation built on Oct. 24, 2024, 1:52 p.m.