vec_assert {vctrs}R Documentation

Assert an argument has known prototype and/or size

Description

[Questioning]

Usage

vec_assert(
  x,
  ptype = NULL,
  size = NULL,
  arg = caller_arg(x),
  call = caller_env()
)

vec_is(x, ptype = NULL, size = NULL)

Arguments

x

A vector argument to check.

ptype

Prototype to compare against. If the prototype has a class, its vec_ptype() is compared to that of x with identical(). Otherwise, its typeof() is compared to that of x with ==.

size

A single integer size against which to compare.

arg

Name of argument being checked. This is used in error messages. The label of the expression passed as x is taken as default.

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.

Value

vec_is() returns TRUE or FALSE. vec_assert() either throws a typed error (see section on error types) or returns x, invisibly.

Error types

vec_is() never throws. vec_assert() throws the following errors:

Both errors inherit from "vctrs_error_assert".

Lifecycle

Both vec_is() and vec_assert() are questioning because their ptype arguments have semantics that are challenging to define clearly and are rarely useful.

Vectors and scalars

Informally, a vector is a collection that makes sense to use as column in a data frame. The following rules define whether or not x is considered a vector.

If no vec_proxy() method has been registered, x is a vector if:

If a vec_proxy() method has been registered, x is a vector if:

Otherwise an object is treated as scalar and cannot be used as a vector. In particular:


[Package vctrs version 0.6.5 Index]