islice: Iterator that returns selected elements from an iterable.

Description Usage Arguments Details Value Examples

Description

Constructs an iterator that returns elements from an iterable following the given sequence with starting value start and ending value end. The sequence's step size is given by step.

Usage

1
islice(object, start = 1, end = NULL, step = 1)

Arguments

object

iterable object through which this function iterates

start

the index of the first element to return from object

end

the index of the last element to return from object

step

the step size of the sequence

Details

The iterable given in object is traversed beginning with element having index specified in start. If start is greater than 1, then elements from the object are skipped until start is reached. By default, elements are returned consecutively. However, if the step size is greater than 1, elements in object are skipped.

If stop is NULL (default), the iteration continues until the iterator is exhausted unless end is specified. In this case, end specifies the sequence position to stop iteration.

Value

iterator that returns object in sequence

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
it <- islice(1:5, start=2)
iterators::nextElem(it) # 2
iterators::nextElem(it) # 3
iterators::nextElem(it) # 4
iterators::nextElem(it) # 5

it2 <- islice(1:10, start=2, end=5)
unlist(as.list(it2)) == 2:5

it3 <- islice(1:10, start=2, end=9, step=2)
unlist(as.list(it3)) == c(2, 4, 6, 8)


Search within the itertools2 package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.