take: Extract n steps from a generator

Description Usage Arguments Examples

View source: R/take.R

Description

.simplify uses unlist and reduces lists to vectors in a similar fashion.

Usage

1
take(.generator, .n, .simplify)

Arguments

.generator

A function with the class generator

.n

The number of steps to take

.simplify

If TRUE, let the function try to simplify the output instead of returning a list

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Simplifying to a vector
counter <- generator(0, ~ state + 1)
take(counter, 5)

# Simplifying to a matrix
ran <- generator(c(0, 0), ~ rnorm(2))
take(ran, 5)

# Returning a list
take(ran, 5, FALSE)

michaelquinn32/generators documentation built on May 22, 2019, 9:52 p.m.