EVOLUTION-MANAGER
Edit File: vec_assert.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Assert an argument has known prototype and/or size</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for vec_assert {vctrs}"><tr><td>vec_assert {vctrs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Assert an argument has known prototype and/or size</h2> <h3>Description</h3> <ul> <li> <p><code>vec_is()</code> is a predicate that checks if its input is a vector that conforms to a prototype and/or a size. </p> </li> <li> <p><code>vec_assert()</code> throws an error when the input is not a vector or doesn't conform. </p> </li></ul> <h3>Usage</h3> <pre> vec_assert( x, ptype = NULL, size = NULL, arg = caller_arg(x), call = caller_env() ) vec_is(x, ptype = NULL, size = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>A vector argument to check.</p> </td></tr> <tr valign="top"><td><code>ptype</code></td> <td> <p>Prototype to compare against. If the prototype has a class, its <code><a href="vec_ptype.html">vec_ptype()</a></code> is compared to that of <code>x</code> with <code>identical()</code>. Otherwise, its <code><a href="../../base/html/typeof.html">typeof()</a></code> is compared to that of <code>x</code> with <code>==</code>.</p> </td></tr> <tr valign="top"><td><code>size</code></td> <td> <p>A single integer size against which to compare.</p> </td></tr> <tr valign="top"><td><code>arg</code></td> <td> <p>Name of argument being checked. This is used in error messages. The label of the expression passed as <code>x</code> is taken as default.</p> </td></tr> <tr valign="top"><td><code>call</code></td> <td> <p>The execution environment of a currently running function, e.g. <code>caller_env()</code>. The function will be mentioned in error messages as the source of the error. See the <code>call</code> argument of <code><a href="../../rlang/html/abort.html">abort()</a></code> for more information.</p> </td></tr> </table> <h3>Value</h3> <p><code>vec_is()</code> returns <code>TRUE</code> or <code>FALSE</code>. <code>vec_assert()</code> either throws a typed error (see section on error types) or returns <code>x</code>, invisibly. </p> <h3>Scalars and vectors</h3> <p>Informally, a vector is a collection that makes sense to use as column in a data frame. An object is a vector if one of the following conditions hold: </p> <ul> <li><p> A <code><a href="vec_proxy.html">vec_proxy()</a></code> method is implemented for the class of the object. </p> </li> <li><p> The <a href="../../base/html/typeof.html">base type</a> of the object is atomic: <code>"logical"</code>, <code>"integer"</code>, <code>"double"</code>, <code>"complex"</code>, <code>"character"</code>, <code>"raw"</code> </p> </li> <li><p> The object is a <a href="../../base/html/data.frame.html">data.frame</a>. </p> </li> <li><p> The base type is <code>"list"</code>, and one of: </p> <ul> <li><p> The object is a bare <code>"list"</code> without a <code>"class"</code> attribute. </p> </li> <li><p> The object explicitly inherits from <code>"list"</code>. That is, the <code>"class"</code> attribute contains <code>"list"</code> and <code>inherits(x, "list")</code> is <code>TRUE</code>. </p> </li></ul> </li></ul> <p>Otherwise an object is treated as scalar and cannot be used as a vector. In particular: </p> <ul> <li> <p><code>NULL</code> is not a vector. </p> </li> <li><p> S3 lists like <code>lm</code> objects are treated as scalars by default. </p> </li> <li><p> Objects of type <a href="../../base/html/expression.html">expression</a> are not treated as vectors. </p> </li> <li><p> Support for S4 vectors is currently limited to objects that inherit from an atomic type. </p> </li> <li><p> Subclasses of <a href="../../base/html/data.frame.html">data.frame</a> that <em>append</em> their class to the <code>"class"</code> attribute are not treated as vectors. If you inherit from an S3 class, always prepend your class to the <code>"class"</code> attribute for correct dispatch. </p> </li></ul> <h3>Error types</h3> <p><code>vec_is()</code> never throws. <code>vec_assert()</code> throws the following errors: </p> <ul> <li><p> If the input is not a vector, an error of class <code>"vctrs_error_scalar_type"</code> is raised. </p> </li> <li><p> If the prototype doesn't match, an error of class <code>"vctrs_error_assert_ptype"</code> is raised. </p> </li> <li><p> If the size doesn't match, an error of class <code>"vctrs_error_assert_size"</code> is raised. </p> </li></ul> <p>Both errors inherit from <code>"vctrs_error_assert"</code>. </p> <hr /><div style="text-align: center;">[Package <em>vctrs</em> version 0.5.0 <a href="00Index.html">Index</a>]</div> </body></html>