irep: Iterator that replicates elements of an iterable object

Description Usage Arguments Details Value Examples

View source: R/irep.r

Description

Constructs an iterator that replicates the values of an object.

Usage

1
2
3
irep(object, times = 1, length.out = NULL, each = NULL)

irep_len(object, length.out = NULL)

Arguments

object

object to return indefinitely.

times

the number of times to repeat each element in object

length.out

non-negative integer. The desired length of the iterator

each

non-negative integer. Each element is repeated each times

Details

This function is intended an iterable version of the standard rep function. However, as exception, the recycling behavior of rep is intentionally not implemented.

Value

iterator that returns object

Examples

1
2
3
4
5
6
7
8
it <- irep(1:3, 2)
unlist(as.list(it)) == rep(1:3, 2)

it2 <- irep(1:3, each=2)
unlist(as.list(it2)) == rep(1:3, each=2)

it3 <- irep(1:3, each=2, length.out=4)
as.list(it3)

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

Search within the itertools2 package
Search all R packages, documentation and source code