ipermutations: Iterator that generates all permutations of an iterable...

Description Usage Arguments Details Value Examples

Description

Constructs an iterator generates all permutations of an iterable object. By default, full-length permutations are generated. If m is specified, successive m length permutations are instead generated.

Usage

1
ipermutations(object, m = NULL)

Arguments

object

vector

m

length of permutations. By default, full-length permutations are generated.

Details

The implementation is loosely based on that of Python's itertools.

Value

iterator that generates all permutations of object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
it <- ipermutations(1:3)

iterators::nextElem(it) # c(1, 2, 3)
iterators::nextElem(it) # c(1, 3, 2)
iterators::nextElem(it) # c(3, 1, 2)
iterators::nextElem(it) # c(3, 2, 1)
iterators::nextElem(it) # c(2, 3, 1)
iterators::nextElem(it) # c(2, 1, 3)

it2 <- ipermutations(letters[1:4])
# 24 = 4! permutations of the letters a, b, c, and d
as.list(it2)

ramhiser/itertools2 documentation built on May 26, 2019, 10:09 p.m.