return_from: Jump to or from a frame

View source: R/stack.R

return_fromR Documentation

Jump to or from a frame

Description

[Questioning]

While base::return() can only return from the current local frame, return_from() will return from any frame on the current evaluation stack, between the global and the currently active context.

Usage

return_from(frame, value = NULL)

Arguments

frame

An execution environment of a currently running function.

value

The return value.

Examples

fn <- function() {
  g(current_env())
  "ignored"
}
g <- function(env) {
  h(env)
  "ignored"
}
h <- function(env) {
  return_from(env, "early return")
  "ignored"
}

fn()

tidyverse/rlang documentation built on Oct. 31, 2024, 5:35 p.m.