EVOLUTION-MANAGER
Edit File: name_spec.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: Name specifications</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 name_spec {vctrs}"><tr><td>name_spec {vctrs}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Name specifications</h2> <h3>Description</h3> <p>A name specification describes how to combine an inner and outer names. This sort of name combination arises when concatenating vectors or flattening lists. There are two possible cases: </p> <ul> <li><p> Named vector: </p> <div class="sourceCode"><pre>vec_c(outer = c(inner1 = 1, inner2 = 2)) </pre></div> </li> <li><p> Unnamed vector: </p> <div class="sourceCode"><pre>vec_c(outer = 1:2) </pre></div> </li></ul> <p>In r-lib and tidyverse packages, these cases are errors by default, because there's no behaviour that works well for every case. Instead, you can provide a name specification that describes how to combine the inner and outer names of inputs. Name specifications can refer to: </p> <ul> <li> <p><code>outer</code>: The external name recycled to the size of the input vector. </p> </li> <li> <p><code>inner</code>: Either the names of the input vector, or a sequence of integer from 1 to the size of the vector if it is unnamed. </p> </li></ul> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>name_spec, .name_spec</code></td> <td> <p>A name specification for combining inner and outer names. This is relevant for inputs passed with a name, when these inputs are themselves named, like <code>outer = c(inner = 1)</code>, or when they have length greater than 1: <code>outer = 1:2</code>. By default, these cases trigger an error. You can resolve the error by providing a specification that describes how to combine the names or the indices of the inner vector with the name of the input. This specification can be: </p> <ul> <li><p> A function of two arguments. The outer name is passed as a string to the first argument, and the inner names or positions are passed as second argument. </p> </li> <li><p> An anonymous function as a purrr-style formula. </p> </li> <li><p> A glue specification of the form <code>"{outer}_{inner}"</code>. </p> </li> <li><p> An <code><a href="../../rlang/html/zap.html">rlang::zap()</a></code> object, in which case both outer and inner names are ignored and the result is unnamed. </p> </li></ul> <p>See the <a href="name_spec.html">name specification topic</a>.</p> </td></tr> </table> <h3>Examples</h3> <pre> # By default, named inputs must be length 1: vec_c(name = 1) # ok try(vec_c(name = 1:3)) # bad # They also can't have internal names, even if scalar: try(vec_c(name = c(internal = 1))) # bad # Pass a name specification to work around this. A specification # can be a glue string referring to `outer` and `inner`: vec_c(name = 1:3, other = 4:5, .name_spec = "{outer}") vec_c(name = 1:3, other = 4:5, .name_spec = "{outer}_{inner}") # They can also be functions: my_spec <- function(outer, inner) paste(outer, inner, sep = "_") vec_c(name = 1:3, other = 4:5, .name_spec = my_spec) # Or purrr-style formulas for anonymous functions: vec_c(name = 1:3, other = 4:5, .name_spec = ~ paste0(.x, .y)) </pre> <hr /><div style="text-align: center;">[Package <em>vctrs</em> version 0.5.0 <a href="00Index.html">Index</a>]</div> </body></html>