Learn R Programming

rlang (version 1.1.3)

env_is_user_facing: Is frame environment user facing?

Description

Detects if env is user-facing, that is, whether it's an environment that inherits from:

  • The global environment, as would happen when called interactively

  • A package that is currently being tested

If either is true, we consider env to belong to an evaluation frame that was called directly by the end user. This is by contrast to indirect calls by third party functions which are not user facing.

For instance the lifecycle package uses env_is_user_facing() to figure out whether a deprecated function was called directly or indirectly, and select an appropriate verbosity level as a function of that.

Usage

env_is_user_facing(env)

Arguments

env

An environment.

Escape hatch

You can override the return value of env_is_user_facing() by setting the global option "rlang_user_facing" to:

  • TRUE or FALSE.

  • A package name as a string. Then env_is_user_facing(x) returns TRUE if x inherits from the namespace corresponding to that package name.

Examples

Run this code
fn <- function() {
  env_is_user_facing(caller_env())
}

# Direct call of `fn()` from the global env
with(global_env(), fn())

# Indirect call of `fn()` from a package
with(ns_env("utils"), fn())

Run the code above in your browser using DataLab