Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/t-kalinowski/listarrays
Functional tools for working with R arrays
https://github.com/t-kalinowski/listarrays
Last synced: 10 days ago
JSON representation
Functional tools for working with R arrays
- Host: GitHub
- URL: https://github.com/t-kalinowski/listarrays
- Owner: t-kalinowski
- License: gpl-3.0
- Created: 2018-02-25T20:52:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-19T14:36:33.000Z (7 months ago)
- Last Synced: 2024-10-12T04:47:39.837Z (25 days ago)
- Language: R
- Homepage: https://t-kalinowski.github.io/listarrays/
- Size: 543 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# listarrays[![CRAN status](https://www.r-pkg.org/badges/version/listarrays)](https://cran.r-project.org/package=listarrays)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/last-month/listarrays?color=blue)](https://r-pkg.org/pkg/listarrays)A toolbox for working with R arrays in a functional programming style. Flexibly
split, bind, reshape, modify, subset, and name arrays.The package provides:
+ `split_on_dim()` and `split_along_dim()` which take an array and return a list.
+ `bind_on_dim()` and `bind_as_dim()` take a list and return an array.
+ `modify_along_dim()` takes an array, calls the passed function `.f()` on each
subset of the specified dimension, and returns an array of the same shape.
(think of this as a safer and sometimes faster alternative to `base::apply()`
that is guaranteed to return an array of the same shape as it received)
+ `extract_dim()` a wrapper around `[` that allows you to specify the dimension
being subset as a function argument. For example, `extract_dim(X, 1, idx)`
will extract `idx` on the first dimension, regardless how many dimensions are in
the array `X`. Contrast this with the base alternative `X[idx,,]`, where you
have to match the number of commas `,` to the number of dimensions in `X`.
+ Many of the functions have two variants `*_rows()` and `*_cols()` for the two
most common case of the first and last dimension. For example
`split_on_rows()` which is equivalent to `split_on_dim(X, 1)` and
`split_on_cols()` which is equivalent to `split_on_dim(X, -1)`
* `set_dim()` and `set_dimnames()`, pipe-friendly and more flexible
versions of `dim<-` and `dimnames<-`
* `dim2()<-`, `set_dim2()`, `array2()`, which reshape or fills arrays using
row-major (C-style) semantics
* A handful of lower-level helpers that abstract out patterns commonly
encountered while working with arrays, for example `expand_dims()`
(the inverse of `base::drop()`, or `seq_along_rows()` (a
combination of `seq_along()` and `nrow()`).* A set of functions that help encode atomic vectors as `onehot()` binary
matrix's and `decode_onehot()` back into atomic vectors. (for example if
training a neural network with keras)* Many of the functions work recursively if provided a list of arrays.
## Installation
You can install listarrays from CRAN with:
```{r, eval=FALSE}
install.packages("listarrays")
```Or install the development version from github with:
``` {r, eval=FALSE}
devtools::install_github("t-kalinowski/listarrays")
```