Learn R Programming

iterors (version 1.0.1)

makeIwrapper: Iterator Constructor-Constructor Function Wrapper

Description

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 i_rnorm is defined as i_rnorm <- makeIwrapper(rnorm).

Usage

makeIwrapper(FUN)

Value

An iterator that is a wrapper around the corresponding function.

Arguments

FUN

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

Details

The resulting iterator constructor will have additional optional arguments:

  • count specifies the number of times the resulting iterator should fire.

  • independent which enables independent tracking of the random number seed.

  • seed specifies the starting seed.

  • kind specifies the randum number generator used

  • normal.kind and sample.kind are passed along to set.seed

For more details on these arguments see rng.

Original version appeared in the iterators package.

Examples

Run this code

# 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)
nextOr(it)
nextOr(it)
nextOr(it, NULL)  # NULL

Run the code above in your browser using DataLab