Limited Memory List

# use this to knit the README.md file
knitr::knit(input="README.Rmd", output = "README.md")

The purpose of this package is to implement simple lists and vectors which automatically drop the oldest elements when the number of elements grows large enough.

Install

You can install from github:

library(remotes)
remotes::install_github("mrparker909/LimitedMemoryList")

Examples

First, load the library:

library(LimitedMemoryList)

Lists

Create a new list:

my_list = list()

Add elements to the list, limiting the memory to 3 items:

my_list = LMList("please",my_list,3)
my_list = LMList("tree",  my_list,3)
my_list = LMList("my",    my_list,3)
my_list = LMList("climb", my_list,3)
my_list = LMList("don't", my_list,3)
my_list

Because the list memory is capped at 3, the first two elements were dropped to make room for the new elements.

Vectors

Create a new vector:

my_vec = c()

Add elements to the vector, limiting the memory to 4 items:

my_vec = LMc("please",my_vec,4)
my_vec = LMc("tree",  my_vec,4)
my_vec = LMc("my",    my_vec,4)
my_vec = LMc("climb", my_vec,4)
my_vec = LMc("don't", my_vec,4)
my_vec

Since the vector memory is capped at 4, the last element was dropped to make room for the newest element.



mrparker909/LimitedMemoryList documentation built on Nov. 4, 2019, 7:35 p.m.