Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonocarroll/vec

A New Vector Class With Added Functionality
https://github.com/jonocarroll/vec

Last synced: about 2 months ago
JSON representation

A New Vector Class With Added Functionality

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# vec

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)

The goal of vec is to reinvent the "vector" class with new and improved
functionality.

## Installation

You can install the development version of {vec} like so:

``` r
# install.packages("remotes")
remotes::install_github("jonocarroll/vec")
```

## Examples

{vec} provides a new class extending R's atomic vectors which enables some new
functionality.

```{r example}
library(vec)
```

### Subsetting via Functions

Along with some built-in vector operations such as `is_even()`, {vec} enables
subsetting with a function or formula, and in-place replacements with the same

```{r}
x <- as_vec(1:10)
x

x[~is_even(.)]

x[is_even]

x[is_even] <- 0
x
```

See the [vignette](https://jonocarroll.github.io/vec/articles/functions.html)
for more details.

### Rotating

While not specific to {vec}, this package provides a ring-buffer-like function
which rotates a vector through `n` positions

```{r}
x <- as_vec(1:5)
x

rotate(x, n = 1)
rotate(x, n = 2)
rotate(x, n = -1)
```

## Other Use Cases

I'm interested in what else a new vector class could bring to R. Add an
[Issue](https://github.com/jonocarroll/vec) if you can think of one!