https://github.com/r-lib/vctrs
Generic programming with typed R vectors
https://github.com/r-lib/vctrs
r s3-vectors
Last synced: 5 months ago
JSON representation
Generic programming with typed R vectors
- Host: GitHub
- URL: https://github.com/r-lib/vctrs
- Owner: r-lib
- License: other
- Created: 2016-09-06T21:32:53.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2026-01-21T21:25:40.000Z (6 months ago)
- Last Synced: 2026-01-22T09:58:23.315Z (6 months ago)
- Topics: r, s3-vectors
- Language: C
- Homepage: https://vctrs.r-lib.org
- Size: 29.2 MB
- Stars: 300
- Watchers: 10
- Forks: 73
- Open Issues: 182
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
- jimsghstars - r-lib/vctrs - Generic programming with typed R vectors (C)
README
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
[](https://app.codecov.io/gh/r-lib/vctrs)

[](https://github.com/r-lib/vctrs/actions/workflows/R-CMD-check.yaml)
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:
```{r, eval = FALSE}
install.packages("vctrs")
```
Alternatively, if you need the development version, install it with:
```{r, eval = FALSE}
# install.packages("pak")
pak::pak("r-lib/vctrs")
```
## Usage
```{r}
library(vctrs)
# Sizes
vec_size_common(1, 1:10)
str(vec_recycle_common(1, 1:10))
# Prototypes
vec_ptype_common(FALSE, 1L, 2.5)
str(vec_cast_common(FALSE, 1L, 2.5))
```
