icycle {itertools2}R Documentation

Iterator that cycles indefinitely through an iterable object

Description

Constructs an iterator that returns an iterable object in sequence over and over again.

Usage

icycle(object, times = NULL)

Arguments

object

object to cycle indefinitely.

times

the number of times object is returned. If NULL (default), object is returned indefinitely.

Details

Runs indefinitely unless the times argument is specified.

Value

iterator that returns object in sequence

Examples

it <- icycle(1:3)
iterators::nextElem(it) # 1
iterators::nextElem(it) # 2
iterators::nextElem(it) # 3
iterators::nextElem(it) # 1
iterators::nextElem(it) # 2
iterators::nextElem(it) # 3
iterators::nextElem(it) # 1

it2 <- icycle(1:3, times=2)
as.list(it2)

# Can return the results from a function.
it3 <- icycle(function() rnorm(1))
iterators::nextElem(it)
iterators::nextElem(it)
iterators::nextElem(it)
iterators::nextElem(it)

[Package itertools2 version 0.1.1 Index]