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.


You can install flifo from GitHub with:

# install.packages("devtools")


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

# Create an empty LIFO
s <- lifo()
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))
size(s)# in bytes
pop(s) # get the last element inserted

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 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")
pop(s) # generates an error


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 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.


0.1.5 by Paul Poncet, 7 months ago

Report a bug at

Browse source code at

Authors: Paul Poncet [aut, cre]

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports bazar, pryr

Suggests knitr, stats, testthat

See at CRAN