Vector Helpers

Defines new notions of prototype and size that are used to provide tools for consistent and well-founded type-coercion and size-recycling, and are in turn connected to ideas of type- and size-stability useful for analysing function interfaces.


vctrs

Codecov testcoverage Lifecycle:maturing R-CMD-check

There are three main goals to the vctrs package, each described in a vignette:

  • To propose vec_size() and vec_ptype() as alternatives to length() and class(); vignette("type-size"). These definitions are paired with a framework for size-recycling and type-coercion. ptype should evoke the notion of a prototype, i.e. the original or typical form of something.

  • To define size- and type-stability as desirable function properties, use them to analyse existing base functions, and to propose better alternatives; vignette("stability"). This work has been particularly motivated by thinking about the ideal properties of c(), ifelse(), and rbind().

  • To provide a new vctr base class that makes it easy to create new S3 vectors; vignette("s3-vector"). vctrs provides methods for many base generics in terms of a few new vctrs generics, making implementation considerably simpler and more robust.

vctrs is a developer-focussed package. Understanding and extending vctrs requires some effort from developers, but should be invisible to most users. It’s our hope that having an underlying theory will mean that users can build up an accurate mental model without explicitly learning the theory. vctrs will typically be used by other packages, making it easy for them to provide new classes of S3 vectors that are supported throughout the tidyverse (and beyond). For that reason, vctrs has few dependencies.

Installation

Install vctrs from CRAN with:

install.packages("vctrs")

Alternatively, if you need the development version, install it with:

# install.packages("pak")
pak::pak("r-lib/vctrs")

Usage

library(vctrs)

# Sizes
vec_size_common(1, 1:10)
#> [1] 10
str(vec_recycle_common(1, 1:10))
#> List of 2
#>  $ : num [1:10] 1 1 1 1 1 1 1 1 1 1
#>  $ : int [1:10] 1 2 3 4 5 6 7 8 9 10

# Prototypes
vec_ptype_common(FALSE, 1L, 2.5)
#> numeric(0)
str(vec_cast_common(FALSE, 1L, 2.5))
#> List of 3
#>  $ : num 0
#>  $ : num 1
#>  $ : num 2.5

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("vctrs")

0.7.3 by Davis Vaughan, 6 months ago


https://vctrs.r-lib.org/, https://github.com/r-lib/vctrs


Report a bug at https://github.com/r-lib/vctrs/issues


Browse source code at https://github.com/cran/vctrs


Authors: Hadley Wickham [aut] , Lionel Henry [aut] , Davis Vaughan [aut, cre] , data.table team [cph] (Radix sort based on data.table's forder() and their contribution to R's order()) , Posit Software , PBC [cph, fnd]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports cli, glue, lifecycle, rlang

Suggests bit64, covr, crayon, dplyr, generics, knitr, pillar, pkgdown, rmarkdown, testthat, tibble, waldo, withr, xml2, zeallot


Imported by AmigaFFH, AzureCosmosR, AzureStor, AzureTableStor, CodelistGenerator, DSIR, EGM, ForestElementsR, GeRnika, HealthMarkers, LLMR, LabApplStat, Microsoft365R, PhenotypeR, REDCapCAST, REDCapTidieR, ROCFTP.MMS, RSDA, Racmacs, STATcubeR, Signac, SpatialKDE, a5R, accept, actibase, actxps, adas.utils, adfExplorer, adj, adobeanalyticsr, adverbial, ageutils, agua, agvgd, airship, amp.dm, arcgisrouting, arrow, bage, baizer, bignum, bigsnpr, bioseq, birdie, blends, blob, blockr.core, blockstrap, bregr, brolgar, butcher, calcal, campsis, cards, carwatch, causalgenerics, censored, cereal, charr, cjar, cleaner, clock, codebook, connectapi, cookiemonster, cookies, coursekata, crawlee, crew.cluster, crossmap, csquares, cubble, dataset, datetimeoffset, dbglm, dbplyr, debkeepr, decimal, decor, densityarea, deriva, dials, dibble, distionary, distplyr, distributional, dm, downlit, dplyr, drake, dtlg, dtplyr, duckplyr, eam, easycensus, edibble, edr4r, ellmer, embed, epidatr, era, ernest, ethiodate, fable.bayesRecon, fabletools, fabricQueryR, falsifyr, famish, fasster, fastplyr, favr, feasts, ffp, filecacher, filtro, findInFiles, finetune, ftExtra, furrr, gasanalyzer, geomtextpath, ggInterval, ggalign, gganimate, ggarrow, ggborderline, ggcircular, ggcleveland, ggdensity, ggdiagram, ggdist, ggfacto, ggforce, gggenomes, ggh4x, gghexsize, ggicons, ggip, ggiraph, gglinedensity, gglm, ggmapinset, ggpattern, ggplot2, ggpp, ggragged, ggrain, ggraph, ggscribe, ggshadow, ggside, ggtibble, ggtime, ggvegan, glymotif, glyrepr, goat, godley, googledrive, googlesheets4, gratia, groupr, gt, gtsummary, h3o, halfmoon, hardhat, haven, heckmanGE, heemod, heritable, hms, httr2, icomb, icons, igcop, igraph, immunarch, important, incidence2, infer, ipaddress, ivs, japanstat, jentre, jirar, jpcity, jpgrid, jpmesh, jpstat, keyed, kindling, labelled, lay, legendry, lvmisc, marquee, mascarade, maskr, matrixset, metamorphr, meteospain, mixtime, mkin, mlstats, modelenv, modelr, move2, multidplyr, naniar, navigatr, nestr, node2vec, od, odbc, omopgenerics, openFDA, opencpu, orderly, palette, palettes, pammtools, panelr, parsnip, partialised, parttime, phinterval, pillar, pkgmatch, plotly, plume, pmrm, poputils, posterior, powerjoin, prefio, probably, profile, profvis, projects, propensity, prt, ptvalue, purrr, pxmake, pysparklyr, qgisprocess, quallmer, r3js, raddr, ragnar, rar, rayrender, rayvertex, readODS, recipes, redist, redistmetrics, reliabilitydiag, resquin, restatis, retroharmonize, rextendr, ricu, riingo, riskmetric, rsample, rsurveycto, rtestim, rvec, rxode2, rxref, salesforcer, saros, saros.base, schmear, sdtm.oak, seekr, selenider, sensortowerR, sfcr, shide, simTool, skimr, slider, smvr, sparklyr, sparkxgb, sparsevctrs, spatialsample, spdgp, srvyr, stacks, statim, stbl, stickyr, stratigraphr, stringr, styler, supernova, syrup, tabnet, tabstats, tabtibble, tabxplor, tailor, tarchetypes, targets, taylor, tdarec, term, textrecipes, tf, tfevents, tfhub, themis, tibble, tibbletime, tibblify, tidyREDCap, tidyRSS, tidybayes, tidychangepoint, tidyclust, tidydfidx, tidypaleo, tidyplus, tidypopgen, tidyposterior, tidyr, tidyselect, tidyseurat, tidysmd, tidysq, tidysynthesis, tidytable, tidyterra, tidytext, tidywikidatar, timbr, timeplyr, tinylens, toposort, transformr, treesitter, trending, trendseries, triptych, tsibble, tsibbledata, tsibbletalk, tune, tweenr, utile.tools, vecvec, versus, vetiver, vitae, vital, vroom, vrpr, waywiser, weird, wikkitidy, wkpool, wompwomp, workflows, workflowsets, xgxr, xlr, xmap, xpose.xtras, yaap, yamlet, yardstick, zentraR.

Depended on by taxa.

Suggested by AMR, AzureGraph, CPGLIB, CSHShydRology, Cleanet, DBI, DBItest, DistributionIV, FIAstemmap, MiscMetabar, NeEDS4BigData, PLindleyROC, PSGD, SplitGLM, arcgislayers, arcgisutils, asympDiag, bench, bigD, blvim, charcuterie, confcons, cpp11, cppally, cutpointr, delimtools, distributions3, duckdb, editbl, epocakir, errors, fastai, fauxnaif, fs, gdalraster, geos, gh, glue, gmapsdistance, grates, icebergr, ir, irid, jsonlite, lifecycle, logbin, lubridate, matchedcc, mlr3forecast, mobsim, multifear, nanoarrow, pairwiseLLM, pctax, pcvr, pulso, quantities, ravetools, rimu, rlang, rmarkdown, s2, sacRebleu, serp, sf, sfdep, sftime, stepSplitReg, survinger, testthat, tidyfun, tidyjson, tidytuesdayR, tinylabels, twbparser, units, vosonSML, winch, wk.


See at CRAN