islice {itertools2}R Documentation

Iterator that returns selected elements from an iterable.

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

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

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)

[Package itertools2 version 0.1.1 Index]