Learn R Programming

vctrs

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

Copy Link

Version

Install

install.packages('vctrs')

Monthly Downloads

1,590,672

Version

0.7.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Davis Vaughan

Last Published

January 16th, 2026

Functions in vctrs (0.7.0)

as-is

AsIs S3 class
faq-compatibility-types

FAQ - How is the compatibility of vector types decided?
data_frame

Construct a data frame
faq-error-incompatible-attributes

FAQ - Error/Warning: Some attributes are incompatible
faq-error-scalar-type

FAQ - Error: Input must be a vector
fields

Tools for accessing the fields of a record.
howto-faq-coercion-data-frame

FAQ - How to implement ptype2 and cast methods? (Data frames)
df_list

Collect columns for data frame construction
howto-faq-coercion

FAQ - How to implement ptype2 and cast methods?
df_ptype2

Coercion between two data frames
list_drop_empty

Drop empty elements from a list
list_combine

Combine a list of vectors
list_unchop

Combine a list of vectors
list-of-attributes

list_of attributes
howto-faq-fix-scalar-type-error

FAQ - Why isn't my class treated as a vector?
internal-faq-matches-algorithm

Internal FAQ - Implementation of vec_locate_matches()
internal-faq-ptype2-identity

Internal FAQ - vec_ptype2(), NULL, and unspecified vectors
list_of

Construct a list of homogenous vectors
list_of_transpose

Transpose a list of homogenous vectors
vec_ptype_full.integer64

64 bit integers
name_spec

Name specifications
new_data_frame

Assemble attributes for data frame construction
new_list_of

Create list_of subclass
obj_is_list

List checks
missing

Missing values
new_rcrd

rcrd (record) S3 class
maybe_lossy_cast

Lossy cast error
new_date

Date, date-time, and duration S3 classes
new_vctr

vctr (vector) S3 class
new_factor

Factor/ordered factor S3 class
runs

Runs
%0%

Default value for empty vectors
s3_register

Register a method for a suggested dependency
theory-faq-recycling

FAQ - How does recycling work in vctrs and the tidyverse?
parallel-operators

Parallel any() and all()
theory-faq-coercion

FAQ - How does coercion work in vctrs?
reference-faq-compatibility

FAQ - Is my class compatible with vctrs?
obj_print

print() and str() generics.
order-radix

Order and sort vectors
table

Table S3 class
vec-case-and-replace

Recode and replace using logical conditions
vctrs-unspecified

Unspecified vectors and prototype finalisation
vec-set

Set operations
vec_arith

Arithmetic operations
vec-rep

Repeat a vector
vec-recode-and-replace

Recode and replace values
vctrs-package

vctrs: Vector Helpers
vctrs-data-frame

vctrs methods for data frames
vctrs-conditions

Custom conditions for vctrs package
vec_as_index

Convert to an index vector
vec_cbind_frame_ptype

Frame prototype
vec_as_names

Retrieve and repair names
vec_cast

Cast a vector to a specified type
vec_chop

Chopping
vec_c

Combine many vectors into one vector
vec_as_subscript

Convert to a base subscript type
vec_as_location

Create a vector of locations
vec_as_names_legacy

Repair names with legacy method
vec_bind

Combine many data frames into one data frame
vec_assert

Assert an argument has known prototype and/or size
vec_count

Count unique values in a vector
vec_detect_complete

Complete
vec_duplicate

Find duplicated values
vec_expand_grid

Create a data frame from all combinations of the inputs
vec_compare

Compare two vectors
vec_default_cast

Default cast and ptype2 methods
vec_equal_na

Missing values
vec_equal

Equality
vec_data

Extract underlying data
vec_empty

Is a vector empty
vec_match

Find matching observations across vectors
vec_interleave

Interleave many vectors into one vector
vec_fill_missing

Fill in missing values with the previous or following value
vec_is_list

List checks
vec_init

Initialize a vector
vec_if_else

Vectorized if-else
vec_locate_matches

Locate observations matching specified conditions
vec_math

Mathematical operations
vec_locate_sorted_groups

Locate sorted groups
vec_group

Identify groups
vec_proxy

Proxy and restore
vec_ptype2.logical

Find the common type for a pair of vectors
vec_rank

Compute ranks
vec_order

Order and sort vectors
vec_ptype

Find the prototype of a set of vectors
vec_recycle

Vector recycling
vec_names

Get or set the names of a vector
vec_ptype_full

Vector type as a string
vec_proxy_compare

Comparison and order proxy
vec_proxy_equal

Equality proxy
vec_seq_along

Useful sequences
vector-checks

Vector checks
vec_repeat

Expand the length of a vector
vec_size

Number of observations
vec_split

Split a vector into groups
vec_unique

Find and count unique values
vec_type

Deprecated type functions
vec_unchop

Chopping
vec_slice

Get or set observations in a vector