Don't Get Stuck with Stacks in R

Functions to create and manipulate FIFO (First In First Out), LIFO (Last In First Out), and NINO (Not In or Never Out) stacks in R.


Travis-CI Build Status CRAN_Status_Badge

The flifo package provides a few functions to create and manipulate FIFO (First In First Out), LIFO (Last In First Out), and NINO (Not In or Never Out) stacks in R.

Installation

You can install flifo from GitHub with:

# install.packages("devtools")
devtools::install_github("paulponcet/flifo")

Usage

Functions fifo, lifo, and nino are provided to create empty stacks. For instance:

library(flifo)
 
# Create an empty LIFO
s <- lifo()
print(s)
 
is.empty(s) # TRUE
is.fifo(s)  # FALSE
is.lifo(s)  # TRUE

Then push and pop enable one to add elements to and retrieve elements from the stack, respectively.

# Add values to 's'
push(s, 0.3)
push(s, data.frame(x=1:2, y=2:3))
print(s)
size(s)# in bytes
 
pop(s) # get the last element inserted
size(s)

A maximum number of elements can be specified at the creation of the stack (no limit in the number of elements is the default).

s <- fifo(max_size = 3)
max_size(s)
 
# max_size can be changed
max_size(s) <- 2
push(s, 1)
push(s, 2)
push(s, 3) # generates an error (the stack is full)

If an object exists in the current environment e and is pushed into the stack, it disappears from e:

s <- lifo()
x <- 3.14
exists("x") # TRUE
push(s, x)
exists("x") # FALSE

The nino function creates a stack from which we cannot not retrieve anything:

s <- nino()
push(s, "foo")
print(s)
pop(s) # generates an error

News

flifo 0.1.5

  • 'push()' and 'pop()' can now be called within functions (#1).

flifo 0.1.4

  • Imports 'bazar' instead of 'base2'
  • The length of a NINO stack was not correct.

flifo 0.1.3

  • Changed 'max_height' for 'max_length'

flifo 0.1.2

  • Every stack now has a 'max_height' and a 'max_size' attributes. The 'height' function gives the current number of elements, and the 'size' function gives the size of the stack in bytes.

flifo 0.1.1

  • Now the print method works for NINO stacks.
  • The README.md file is updated.

flifo 0.1.0

  • Creation of the package 'flifo'

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("flifo")

0.1.5 by Paul Poncet, a year ago


https://github.com/paulponcet/flifo


Report a bug at https://github.com/paulponcet/flifo/issues


Browse source code at https://github.com/cran/flifo


Authors: Paul Poncet [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports bazar, pryr

Suggests knitr, stats, testthat


See at CRAN