Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

yield

Yield a value from a generator


Description

The yield() statement suspends generator() functions. It works like return() except that the function continues execution at the yielding point when it is called again.

yield() can be called within loops and if-else branches but for technical reasons it can't be used anywhere in R code:

  • yield() cannot be called as part of a function argument. Code such as list(yield()) is illegal.

  • yield() does not cross function boundaries. You can't use it a lambda function passed to lapply() for instance.

Usage

yield(x)

Arguments

x

A value to yield.

See Also

generator() for examples.


coro

'Coroutines' for R

v1.0.1
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.