collections

High-performance container datatypes for R

103
3
R

output:
github_document:
html_preview: false

d <- read.dcf("DESCRIPTION")
title <- d[colnames(d) == "Title"]
cat(c("# ", paste(trimws(strsplit(title, "\n")[[1]]), collapse = " ")))

check
codecov
CRAN_Status_Badge

Github: https://github.com/randy3k/collections

Documentation: https://randy3k.github.io/collections/

cat(d[colnames(d) == "Description"])

Installation

You can install the released version of collections from CRAN with:

install.packages("collections")

Install the latest development version using

devtools::install_github("randy3k/collections")

Example

library(collections, warn.conflicts = FALSE)

Queue

q <- queue()
q$push(1)$push(2)
q$pop()

Stack

s <- stack()
s$push(1)$push(2)
s$pop()

Deque

dq <- deque()
dq$push(1)$pushleft(2)
dq$pop()

Priority Queue

pq <- priority_queue()
pq$push("not_urgent")
pq$push("urgent", priority = 2)
pq$push("not_as_urgent", priority = 1)
pq$pop()
pq$pop()
pq$pop()

Dictionary. Comparing to R envrionments, dict() does not leak memory and supports various other types of keys.

d <- dict()
e <- new.env()
d$set(e, 1)$set(sum, 2)$set(c(1L, 2L), 3)
d$get(c(1L, 2L))

Ordered Dictionary

d <- ordered_dict()
d$set("b", 1)$set("a", 2)
d$as_list()