Learn R Programming

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

  • t.array() a transpose method for multi-dimensional arrays

  • 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 ofseq_along()andnrow()`).

  • 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:

install.packages("listarrays")

Or install the development version from github with:

devtools::install_github("t-kalinowski/listarrays")

Copy Link

Version

Install

install.packages('listarrays')

Monthly Downloads

524

Version

0.3.1

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Tomasz Kalinowski

Last Published

March 8th, 2020

Functions in listarrays (0.3.1)

onehot_with_decoder

Convert vector to a onehot representation (binary class matrix)
split_on_dim

Split an array along a dimension
shuffle_rows

Shuffle along the first dimension multiple arrays in sync
t.array

transpose an array
set_as_rows

Reshape an array to send a dimension forward or back
seq_along_dim

Sequence along a dimension
set_dimnames

Set dimnames
set_dim

Reshape an array
extract_dim

Extract with [ on a specified dimension
expand_dims

Expand the shape of an array
drop_dimnames

Drop dimnames
ndim

Length of DIM()
map_along_dim

Apply a function across subsets along an array dimension
modify_along_dim

Modify an array by mapping over 1 or more dimensions
DIM

Helpers for working with 1-d arrays
bind_as_dim

Bind arrays along a specified dimension
array2

Make or reshape an array with C-style (row-major) semantics