take {iterors} | R Documentation |
Return the first n elements of an iterable object in a vector.
Description
Returns the first n
elements of an iterable object
as a list.
If n
is larger than the number of elements in object
, the
entire iterator is consumed.
Usage
take(obj, n = 1, mode = "list", ...)
## Default S3 method:
take(obj, n = 1, mode = "list", ...)
## S3 method for class 'iteror'
take(obj, n = 1, mode = "list", ...)
Arguments
obj |
An iterable object. |
n |
The maximum number of elements to extract from the iteror. |
mode |
The mode of vector to return. |
... |
Further arguments may be passed along to the iteror constructor. |
Details
A function take
first appeared in package itertools2
.
It is basically an alias for as.list but defaults to n=1.
Value
a list of the first n
items of the iterable
obj
See Also
concat as.vector.iteror
as.vector.iteror
Examples
take(1:10, 3) # 1 2 3
take(icount(), 10) # 1:10
take(icount(5), 10) # 1 2 3 4 5
[Package iterors version 1.0 Index]