Learn R Programming

container (version 1.0.0)

pop: Get and Remove Element

Description

Search and return an element and remove it afterwards from the object. If the element is not found, signal an error.

Usage

ref_pop(.x, ...)

ref_popleft(.x, ...)

# S3 method for Deque ref_pop(.x, ...)

# S3 method for Deque ref_popleft(.x, ...)

# S3 method for Container ref_pop(.x, index, ...)

# S3 method for dict.table ref_pop(.x, index, ...)

Arguments

.x

any R object.

...

additional arguments to be passed to or from methods.

index

character name or numeric position of value to be popped

Value

For Deque the first (ref_popleft) or last (ref_pop) element of the deque after it was removed.

For Container the value at the given index after it was removed from the Container object. If index is not found, an error is raised.

For dict.table, returns the column at the given index after it was removed from the dict.table. If column does not exist, an error is raised.

Details

All functions work by reference, that is, the original object is altered. ref_pop(.x) tries to access specific values.

ref_popleft(.x) pops first element of a Deque.

See Also

peek()

Examples

Run this code
# NOT RUN {
# Deque
d = deque(1, 2, 3)
ref_pop(d)
ref_popleft(d)

# }
# NOT RUN {
ref_pop(deque())  # pop at empty Deque
# }
# NOT RUN {
# Container
co = container(a = 1, b = 1:3, d = "foo")
ref_pop(co, "b")
ref_pop(co, 1)

# }
# NOT RUN {
ref_pop(co, "x")  # index 'x' not found
# }
# NOT RUN {
# dict.table
dit = dict.table(a = 1:3, b = 4:6)
ref_pop(dit, "a")
ref_pop(dit, 1)

# }
# NOT RUN {
ref_pop(dit, "x")  # index 'x' not found
# }

Run the code above in your browser using DataLab