Search and return an element and remove it afterwards from the object. If the element is not found, signal an error.
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, ...)
any R
object.
additional arguments to be passed to or from methods.
character
name or numeric
position of value to be popped
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.
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
.
# Deque
d = deque(1, 2, 3)
ref_pop(d)
#> [1] 3
ref_popleft(d)
#> [1] 1
try({
ref_pop(deque()) # pop at empty Deque
})
#> Error : pop at empty Deque
# Container
co = container(a = 1, b = 1:3, d = "foo")
ref_pop(co, "b")
#> [1] 1 2 3
ref_pop(co, 1)
#> [1] 1
try({
ref_pop(co, "x") # index 'x' not found
})
#> Error : index 'x' not found
# dict.table
dit = dict.table(a = 1:3, b = 4:6)
ref_pop(dit, "a")
#> [1] 1 2 3
ref_pop(dit, 1)
#> [1] 4 5 6
try({
ref_pop(dit, "x") # index 'x' not found
})
#> Error : index 'x' not found