This tutorial package is meant to go along with my talk vctrs: Creating custom vector classes with the vctrs package at RStudio::conf 2020. Slides from the talk are available here.
debvctrs is an example package to demonstrate the creation of new S3 vector classes using the vctrs package. debvctrs is based on the more complete debkeepr package that integrates non-decimal currencies that use the tripartite system of pounds, shillings, and pence into R. This package is not meant for analytical use, though all aspects of the package work as expected and are fully tested using testthat.
You can install debvctrs from GitHub with remotes:
# install.packages("remotes")
remotes::install_github("jessesadler/debvctrs")
The debvctrs package demonstrates the process for creating two different types of S3-vector classes or types. The deb_decimal
type represents non-decimal currencies in decimalized form and is based on a double vector. It has two attributes: a unit
attribute to record whether the values represent pounds, shillings, or pence and a bases
attribute to determine the bases of the shillings and pence units. The deb_lsd
type uses the record style to maintain the tripartite structure of non-decimal currencies. A record-style vector uses a list of equal-length vectors to designate the components that make up each vector. Like the deb_decimal
type, deb_lsd
has a bases
attribute. For a more thorough introduction to the structure of the two classes and the use of the classes, see the description from the debkeepr package.
The R scripts for the package provide an order for constructing these two S3 vectors with vctrs. This tutorial is based on the S3 vignette from the vctrs package. It will be useful to work through this tutorial with the explanations from the vignette.
deb_decimal()
and deb_lsd()
classesdeb_decimal
class based on a double vector.deb_lsd
class, a record-style vector.deb_decimal
deb_lsd
deb_decimal
and deb_lsd
deb_decimal
deb_lsd
deb_decimal
and deb_lsd
==
, !=
, unique()
, anyDuplicated()
, and is.na()
<
, <=
, >=
, >
, min()
, max()
, and xtfrm()
deb_decimal
deb_lsd
deb_decimal
and deb_lsd
bases
and unit
attributesbases
attributeunit
attributevctrs
that is used in the packagevctrs
parametersAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.