vec_as_subscript: Convert to a base subscript type

View source: R/subscript.R

vec_as_subscriptR Documentation

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,
  call = caller_env()
)

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

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, numeric, 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.

call

The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.


vctrs documentation built on May 29, 2024, 11:39 a.m.