peek_top.rstack: Return the data element at the top of an rstack

Description Usage Arguments Details Value See Also Examples

View source: R/peek_top.rstack.R

Description

Simply returns the data element sitting at the top of the rstack, leaving the rstack alone.

Usage

1
2
## S3 method for class 'rstack'
peek_top(s, ...)

Arguments

s

rstack to peek at.

...

additional arguments to be passed to or from methods (ignored).

Details

Runs in O(1) worst-case time.

Value

data element existing at the top of the rstack.

See Also

without_top for removing the top element.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
s <- rstack()
s <- insert_top(s, "a")
s <- insert_top(s, "b")
e <- peek_top(s)
print(e)
print(s)

## Assigning to the top data element with peek_top:
s <- rstack()
s <- insert_top(s, data.frame(a = 1, b = 1))
s <- insert_top(s, data.frame(a = 1, b = 1))

peek_top(s)$a <- 100
print(s)

peek_top(s) <- data.frame(a = 100, b = 100)

rstackdeque documentation built on May 2, 2019, 4:15 a.m.