i_slice {iterors}R Documentation

Iteror that returns selected elements from an iterable.

Description

Constructs an iteror 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

i_slice(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

...

passed along to iteror(object, ...)

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 Inf (default), the iteration continues until the iteror is exhausted unless end is specified. In this case, end specifies the sequence position to stop iteration.

Originally from package itertools2.

Value

iteror that returns object in sequence

Examples

it <- i_slice(1:5, start=2)
nextOr(it, NULL) # 2
nextOr(it, NULL) # 3
nextOr(it, NULL) # 4
nextOr(it, NULL) # 5

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

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

[Package iterors version 1.0 Index]