i_recycle {iterors}R Documentation

Create a recycling iterator

Description

Create an iterator that recycles a specified iterable. On the first repeat the iterable is buffered into memory until it finishes, then we repeat the same sequence of values.

Usage

i_recycle(iterable, times = Inf, ...)

Arguments

iterable

The iterable to recycle.

times

integer. Number of times to recycle the values . Default value of Inf means to recycle indefinitely.

...

Further arguments will be passed along to iteror.

Details

Originally from the itertools package.

Value

an iteror recycling the values from the underlying iterable.

Examples


# Recycle over 'a', 'b', and 'c' three times
i <- i_recycle(letters[1:3], 3)
as.character(i)

it <- i_recycle(1:3)
nextOr(it, NA) # 1
nextOr(it, NA) # 2
nextOr(it, NA) # 3
nextOr(it, NA) # 1
nextOr(it, NA) # 2
nextOr(it, NA) # 3
nextOr(it, NA) # 1

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


[Package iterors version 1.0 Index]