Learn R Programming

iterors (version 1.0)

i_timeout: Create a timeout iterator

Description

Create an iterator that iterates over another iterator for a specified period of time, and then stops. This can be useful when you want to search for something, or run a test for awhile, and then stop.

Usage

i_timeout(iterable, time, ...)

Value

an iteror yielding values from iterable so long as time is in the future

Arguments

iterable

Iterable to iterate over.

time

The time interval to iterate for, in seconds.

...

passed along to iteror(iterable, ...)

Details

Originally from the itertools package.

Examples

Run this code

# See how high we can count in a tenth of a second
length(as.list(i_timeout(icount(), 0.1)))

Run the code above in your browser using DataLab