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.
You can install from github:
library(remotes)
remotes::install_github("mrparker909/LimitedMemoryList")
First, load the library:
library(LimitedMemoryList)
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
## [[1]]
## [1] "don't"
##
## [[2]]
## [1] "climb"
##
## [[3]]
## [1] "my"
Because the list memory is capped at 3, the first two elements were dropped to make room for the new elements.
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
## [1] "don't" "climb" "my" "tree"
Since the vector memory is capped at 4, the last element was dropped to make room for the newest element.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.