Skip to contents

The makeIwrapper function wraps an R function to produce an iterator constructor. It is used to construct random sampling iterators in this package; for instance irnorm is defined as irnorm <- makeIwrapper(rnorm).

Usage

makeIwrapper(FUN)

Arguments

FUN

a function that generates different values each time it is called; typically one of the standard random number generator functions.

Value

An iterator that is a wrapper around the corresponding function.

Details

The resulting iterator constructors all take an optional count argument which specifies the number of times the resulting iterator should fire. They also have an argument independent which enables independent tracking of the random number seed. The isample function is an example of one such iterator constructoe (as are irnorm, irunif, etc.).

Original version appeared in the iterators package.

Examples


# create an iterator maker for the sample function
mysample <- makeIwrapper(sample)
# use this iterator maker to generate an iterator that will generate three five
# member samples from the sequence 1:100
it <- mysample(1:100, 5, count = 3)
nextOr(it)
#> [1]  7 75 11 77 63
nextOr(it)
#> [1] 98 15 37 14 90
nextOr(it)
#> [1] 49 28 82 59 17
nextOr(it, NULL)  # NULL
#> NULL