goto {async}R Documentation

Coroutine switch with delimited goto.


The switch function implemented for coroutines in the async package is more strict than the one in base R. In a coroutine, switch will always either take one of the given branches or throw an error, whereas base R switch will silently return NULL if no branch matches switch argument. Otherwise, the same conventions apply as base::switch() (e.g. empty switch branches fall through; a character switch may have one unnamed argument as a default.)


goto(branch = NULL)



A character string naming the new branch. If missing or NULL, jumps back to re-evaluate the switch argument.


Coroutine switch also supports a delimited form of goto. Within a branch, goto("other_branch") will stop executing the present branch and jump to the named branch. Calling goto() without arguments will jump back to re-evaluate the switch expression.

If a goto appears in a try-finally call, as in:

   branch=tryCatch({...; goto("otherBranch")},

the finally clause will be executed before switching to the new branch.

[Package async version 0.3.2 Index]