Learn R Programming

⚠️There's a newer version (1.0.5) of this package.Take me there.

container

Update to NEW version 1.0.0 soon on CRAN.

container provides an enhanced version of base R’s list with a carefully designed set of extract, replace, and remove operations that make it easier and safer to work with list-like data structures.

Why container?

  • safe and flexible operations to
    • extract (built-in default values, no unintended NULL)
    • add and replace (mixed indices, no unintended overrides)
    • remove (loose or strict deletion, remove by index or value)
  • compact printing
  • optional reference semantics

In addition, this package provides specialized data structures Deque, Set and Dict and a special class dict.table, designed to extend data.table by container operations to safely Manage data columns with dict.table.

Installation

# Install release version from CRAN
install.packages("container")

# Install development version from GitHub
devtools::install_github("rpahl/container")

Usage

library(container)
co <- container(colors = c("Red", "Green"), numbers = c(1, 2, 3), data = cars)
co
# [colors = ("Red" "Green"), numbers = (1 2 3), data = <<data.frame(50x2)>>]

Safe extract

at(co, "colours")   # oops
# Error: index 'colours' not found
at(co, "colors")
# [colors = ("Red" "Green")]

Safe remove

co <- delete_at(co, "colours")   # oops
# Error: names(s) not found: 'colours'
co <- delete_at(co, "colors")
co
# [numbers = (1 2 3), data = <<data.frame(50x2)>>]

Flexible peek

at(co, "colors")   # oops
# Error: index 'colors' not found
peek_at(co, "colors")
# []
peek_at(co, "colors", .default = c("black", "white"))
# [colors = ("black" "white")]

Safe replace

co <- replace_at(co, num = 1:10)   # oops
# Error: names(s) not found: 'num'
co <- replace_at(co, numbers = 1:10)
co
# [numbers = (1L 2L 3L 4L ...), data = <<data.frame(50x2)>>]

Getting Started

Copy Link

Version

Install

install.packages('container')

Monthly Downloads

426

Version

1.0.0

License

GPL-3

Maintainer

Roman Pahl

Last Published

November 6th, 2021

Functions in container (1.0.0)

DictS3

A Dictionary
OpsArithmetic

Arithmetic Operators
ContainerS3

Container - Enhancing R's list
Iterable

Iterable abstract class interface
Dict

Dict Class
Container

Container Class
DequeS3

Deque - Double-Ended Queue
Deque

Deque Class
Iterator

Iterator Class
OpsCompare

Comparison Operators
OpsExtract

Extract Parts of a Container Object
at

Extract Elements Safely
unpack

Unpack Nested Objects
rotate

Rotate Elements
delete

Delete Container Elements Safely
peek

Peek at Left or Right of a Deque
Set

Set Class
SetS3

Set and ordered Set
peek_at

Peek at Indices
delete_at

Delete Elements at Indices Safely
clear

Clear a Container
at2

Extract Single Elements Safely
add

Add Elements to Containers
addleft

Add Elements to the Left of Deques
clone

Clone an Object
OpsLogic

Logic Operators
discard

Discard Container Elements
has_name

Check for Name
update

Update Object with Elements from Another Object
deprecated

Deprecated Functions
dict.table

Combining Dict and data.table
has

Check for Element
rename

Rename Elements Safely
replace

Replace Values in Containers Safely
OpsReplace

Replace Parts of a Container
OrderedSet

OrderedSet Class
container_options

Set Container Package Options
count

Count Elements
peek_at2

Peek at Single Index
pop

Get and Remove Element
replace_at

Replace Values at Indices Safely
is_empty

Check if Object is Empty
discard_at

Discard Elements at Indices
rev

Reverse Elements
iterS3

Iterate over Sequences