nth {iterors} | R Documentation |
Returns the nth item of an iteror
Description
Returns the n
th item of an iteror
after advancing the
iteror n
steps ahead. If the iteror
is entirely consumed,
the argument or
is returned instead. That is, if either n >
length(iteror)
or n
is 0, then the iteror
is consumed.
Usage
nth(obj, n, or, ...)
Arguments
obj |
an iterable. |
n |
The index of the desired element to return. |
or |
If the iteror finishes before retuning |
... |
passed along to iteror constructor. |
Value
The nth element of the iteror or the result of forcing or
.
See Also
take consume collect
Examples
it <- iteror(1:10)
# Returns 5
nth(it, 5, NA)
it2 <- iteror(letters)
# Returns 'e'
nth(it2, 5, NA)
it3 <- iteror(letters)
# Returns default value of NA
nth(it3, 42, NA)
it4 <- iteror(letters)
# Returns default value of "foo"
nth(it4, 42, or="foo")
[Package iterors version 1.0 Index]