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

vec_as_subscript

Convert to a base subscript type


Description

[Experimental]

Convert i to the base type expected by vec_as_location() or vec_as_location2(). The values of the subscript type are not checked in any way (length, missingness, negative elements).

Usage

vec_as_subscript(
  i,
  ...,
  logical = c("cast", "error"),
  numeric = c("cast", "error"),
  character = c("cast", "error"),
  arg = NULL
)

vec_as_subscript2(
  i,
  ...,
  logical = c("cast", "error"),
  numeric = c("cast", "error"),
  character = c("cast", "error"),
  arg = NULL
)

Arguments

i

An integer, character or logical vector specifying the locations or names of the observations to get/set. Specify TRUE to index all elements (as in x[]), or NULL, FALSE or integer() to index none (as in x[NULL]).

...

These dots are for future extensions and must be empty.

logical, location, character

How to handle logical, numeric, and character subscripts.

If "cast" and the subscript is not one of the three base types (logical, integer or character), the subscript is cast to the relevant base type, e.g. factors are coerced to character. NULL is treated as an empty integer vector, and is thus coercible depending on the setting of numeric. Symbols are treated as character vectors and thus coercible depending on the setting of character.

If "error", the subscript type is disallowed and triggers an informative error.

arg

The argument name to be displayed in error messages when vec_as_location() and vec_as_location2() are used to check the type of a function input.


vctrs

Vector Helpers

v0.3.8
MIT + file LICENSE
Authors
Hadley Wickham [aut], Lionel Henry [aut, cre], Davis Vaughan [aut], data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()), RStudio [cph]
Initial release

We don't support your browser anymore

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