islice: Iterator that returns selected elements from an iterable.

Description Usage Arguments Details Value Examples

View source: R/islice.r

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)

itertools2 documentation built on May 30, 2017, 7:17 a.m.