Readme.md

recollections

Collections for R are collections as can be found in Python's collections module implemented using Rcpp.

Very much a work in progress.

Supported data structures

At the moment recollections exposes the following C++ STL data structures to R:

and several sequences: - Cyclic Sequence - Prime Sequence - Step Sequence

which can be accessed using nextItem(sequence), take(sequence, n) and takeWhile(sequence, fun).

Example use

Dictionary

# Function and indexing style
dict <- recollections::dictionary()
dict['foo'] <- 1L
setValue(dict, 'bar', 2L)
dict['foo'] # 1L
getValue(dict, 'bar')  # 2L

# Pipes
dict <- recollections::dictionary() |>
  setValue('foo', 1L) |>
  setValue('bar', 2L)
dict['bar'] # 2L
dict['foo'] # 1L

Lazy sequences

cycleSeq <- cycleSequence(5, 25, 5)
unlist(take(cycleSeq, 10L))  # [1]  5 10 15 20 25 10 15 20 25 10

primeSeq <- recollections::primeSequence()
for (i in 1:10) {
  cat(nextItem(primeSeq), ' ')  # 2  3  5  7  11  13  17  19  23  29
}
unlist(takeWhile(primeSeq, \(val) val < 50L))  # [1] 31 37 41 43 47
unlist(take(primeSeq, 5L))  # [1] 53 59 61 67 71

stepSeq <- stepSequence(5L, 4L)
unlist(take(stepSeq, 10L))  # [1]  5  9 13 17 21 25 29 33 37 41

API

The data structures have the following S3-methods (where applicable):



bobjansen/recollections documentation built on Feb. 13, 2022, 1:30 p.m.