i_rep {iterors}R Documentation

Repeat values from an iterator.

Description

An analogue of the rep function operating on iterables.

Usage

i_rep(iterable, times = 1, length.out = NULL, each = 1, ...)

Arguments

iterable

The iterable to iterate over repeatedly.

times

How many times to recycle the underlying iteror (via i_recycle).

length.out

The maximum length of output. If this is given times is ignored.

each

The number of times to repeat each element. You can pass a vector (recycled), or another iterable, to repeat each element a varying number of times.

...

further arguments passed along to iteror(iterable, ...)

Details

Note that arguments times and each can work slightly differently from rep; times must always be of length 1; to repeat each element a specific number of times, provide a vector to each rather than times.

Originally from the itertools package.

Value

an iteror yilding and repeating values from iterable.

See Also

base::rep, i_recycle

Examples


as.numeric(i_rep(1:4, 2))
as.numeric(i_rep(1:4, each=2))
as.numeric(i_rep(1:4, each=c(2,2,2,2)))
as.numeric(i_rep(1:4, each=c(2,1,2,1)))
as.numeric(i_rep(1:4, each=2, len=4))
as.numeric(i_rep(1:4, each=2, len=10))
as.numeric(i_rep(1:4, each=2, times=3))

# Note `rep` makes `times` behave like `each` when given a vector.
# `i_rep` does not reproduce this behavior; give the vector to `each`.
# These are equivalent:
as.numeric(i_rep(1:4, each = 1:8, times=2))
rep(rep(1:4, times=2), times=1:8)


[Package iterors version 1.0 Index]