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

frame_position

Find the position or distance of a frame on the evaluation stack


Description

Deprecated lifecycle

The frame position on the stack can be computed by counting frames from the global frame (the bottom of the stack, the default) or from the current frame (the top of the stack).

Usage

frame_position(frame, from = c("global", "current"))

Arguments

frame

The environment of a frame. Can be any object with a get_env() method. Note that for frame objects, the position from the global frame is simply frame$pos. Alternatively, frame can be an integer that represents the position on the stack (and is thus returned as is if from is "global".

from

Whether to compute distance from the global frame (the bottom of the evaluation stack), or from the current frame (the top of the evaluation stack).

Details

While this function returns the position of the frame on the evaluation stack, it can safely be called with intervening frames as those will be discarded.

Life cycle

These functions are deprecated and replaced by trace_back().

Examples

fn <- function() g(environment())
g <- function(env) frame_position(env)

# frame_position() returns the position of the frame on the evaluation stack:
fn()
identity(identity(fn()))

# Note that it trims off intervening calls before counting so you
# can safely nest it within other calls:
g <- function(env) identity(identity(frame_position(env)))
fn()

# You can also ask for the position from the current frame rather
# than the global frame:
fn <- function() g(environment())
g <- function(env) h(env)
h <- function(env) frame_position(env, from = "current")
fn()

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

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