Learn R Programming

rlang

rlang is a collection of frameworks and APIs for programming with R.

Frameworks

Two comprehensive frameworks are implemented in rlang.

  • tidy eval, a programmable data-masking framework used in tidyverse packages like dplyr and ggplot2. As a user, you will encounter the embracing operator {{ and name injection with the glue operators "{" and "{{".

  • rlang errors, a set of tools to signal and display errors. This includes backtrace capture with global_entrace() and backtrace display with last_error() and last_warnings(). Use abort() to create errors with bullet lists, structured metadata, and error chaining support.

    The display of error messages is optimised for bullet lists and chained errors and optionally integrates with the cli package (see local_use_cli()).

Argument intake

A set of tools help you check, validate, and preprocess arguments.

  • Checking function arguments, e.g. arg_match(), check_required(), and check_exclusive().

  • Checking dots, e.g. check_dots_used() and check_dots_empty().

  • Collecting dynamic dots, e.g. list2(). These dots support splicing with !!! and name injection with the glue operators "{" and "{{".

Programming interfaces

rlang provides various interfaces for working with R and R objects.

  • The R session, e.g. check_installed(), on_load(), and on_package_load().

  • Environments, e.g. env(), env_has(), env_get(), env_bind(), env_unbind(), env_print(), and local_bindings().

  • Evaluation, e.g. inject() and eval_bare().

  • Calls and symbols, e.g. call2(), is_call(), is_call_simple(), data_sym(), and data_syms().

  • Functions, e.g. new_function() and as_function(). The latter supports the purrr-style formula notation for lambda functions.

Installation

Install the released version of rlang from CRAN:

install.packages("rlang")

Or install the development version from GitHub with:

# install.packages("pak")
pak::pkg_install("r-lib/rlang")

Code of Conduct

Please note that the rlang project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('rlang')

Monthly Downloads

1,442,500

Version

1.1.5

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Lionel Henry

Last Published

January 17th, 2025

Functions in rlang (1.1.5)

are_na

Test for missing values
args_error_context

Documentation anchor for error arguments
cnd_type

What type is a condition?
arg_match

Match an argument to a character vector
is_installed

Are packages installed in any of the libraries?
call_fn

Extract function from a call
box

Box a value
call_inspect

Inspect a call
args_data_masking

Argument type: data-masking
inject

Inject objects in an R expression
env_bind

Bind symbols to objects in an environment
get_env

Get or set the environment of an object
as_name

Extract names from symbols
env_binding_lock

Lock or unlock environment bindings
cnd_muffle

Muffle a condition
exprs_auto_name

Ensure that all elements of a list of expressions are named
cnd_signal

Signal a condition object
env_inherits

Does environment inherit from another environment?
glue-operators

Name injection with "{" and "{{"
is_integerish

Is a vector integer-like?
env

Create a new environment
last_warnings

Display last messages and warnings
call_modify

Modify the arguments of a call
args_dots_empty

Helper for consistent documentation of empty dots
call2

Create a call
fn_fmls

Extract arguments from a function
env_has

Does an environment have or see bindings?
as_utf8_character

Coerce to a character vector and attempt encoding conversion
as_data_mask

Create a data mask
as_box

Convert object to a box
call_args

Extract arguments from a call
env_cache

Cache a value in an environment
caller_arg

Find the caller argument for error messages
as_string

Cast symbol to string
env_is_user_facing

Is frame environment user facing?
env_lock

Lock an environment
is_formula

Is object a formula?
format_error_bullets

Format bullets for error messages
string

Create a string
as_closure

Transform to a closure
call_match

Match supplied arguments to function definition
is_callable

Is an object callable?
dyn-dots

Dynamic dots features
raw_deparse_str

Serialize a raw vector to a string
is_function

Is object a function?
has_length

How long is an object?
is_expression

Is an object an expression?
global_handle

Register default global handlers
names_inform_repair

Inform about name repair
catch_cnd

Catch a condition
args_dots_used

Helper for consistent documentation of used dots
as_function

Convert to function
inherits_any

Does an object inherit from a set of classes?
check_dots_empty0

Check that dots are empty (low level variant)
check_dots_empty

Check that dots are empty
embrace-operator

Embrace operator {{
done

Box a final value for early termination
sym

Create a symbol or list of symbols
topic-embrace-non-args

Does {{ work on regular objects?
topic-metaprogramming

Metaprogramming patterns
bare-type-predicates

Bare type predicates
dots_values

Evaluate dots with preliminary splicing
list2

Collect dynamic dots in a list
topic-embrace-constants

Why are strings and other constants enquosed in the empty environment?
names2

Get names of a vector
rlang_backtrace_on_error

Display backtrace on error
child_env

Create a child environment
as_label

Create a default name for an R object
is_reference

Is an object referencing another?
rlang-package

rlang: Functions for Base Types and Core R and 'Tidyverse' Features
env_browse

Browse environments
quosure-tools

Quosure getters, setters and predicates
vector-construction

Create vectors
exec

Execute a function
cnd_inherits

Does a condition or its ancestors inherit from a class?
cnd

Create a condition object
env_print

Pretty-print an environment
expr

Defuse an R expression
switch_type

Dispatch on base types
eval_bare

Evaluate an expression in an environment
topic-multiple-columns

Taking multiple columns without ...
expr_label

Turn an expression to a label
env_bury

Mask bindings by defining symbols deeper in a scope
vector-coercion

Coerce an object to a base type
dot-data

.data and .env pronouns
defusing-advanced

Advanced defusal operators
eval_tidy

Evaluate an expression with quosures and pronoun support
check_exclusive

Check that arguments are mutually exclusive
dots_n

How many arguments are currently forwarded in dots?
bytes-class

Human readable memory sizes
empty_env

Get the empty environment
enquo

Defuse function arguments
cnd_message

Build an error message from parts
injection-operator

Injection operator !!
check_dots_unnamed

Check that all dots are unnamed
missing

Missing values
chr_unserialise_unicode

Translate unicode points to UTF-8
check_required

Check that argument is supplied
entrace

Add backtrace from error handler
expr_print

Print an expression
env_clone

Clone or coalesce an environment
local_options

Change global options
fn_env

Return the closure environment of a function
env_binding_are_active

What kind of environment binding?
englue

Defuse function arguments with glue
global_prompt_install

Prompt user to install missing packages
env_parent

Get parent environments
rlib_trace_spec

Backtrace specification
ffi_standalone_types_check

Internal API for standalone-types-check
env_unbind

Remove bindings from an environment
dots_splice

Splice lists
is_lang

Is object a call?
env_poke

Poke an object in an environment
is_copyable

Is an object copyable?
env_get

Get an object in an environment
is_call

Is object a call?
duplicate

Duplicate an R object
expr_interp

Process unquote operators in a captured expression
env_unlock

Unlock an environment
fn_body

Get or set function body
is_dictionaryish

Is a vector uniquely named?
env_depth

Depth of an environment chain
is_pairlist

Is object a node or pairlist?
invoke

Invoke a function with a list of arguments
is_true

Is object identical to TRUE or FALSE?
flatten

Flatten or squash a list of lists into a simpler vector
f_rhs

Get or set formula components
new_node

Helpers for pairlist and language nodes
rep_along

Create vectors matching the length of a given vector
new_weakref

Create a weak reference
quo_expr

Squash a quosure
type_of

Base type of an object
has_name

Does an object have an element with this name?
return_from

Jump to or from a frame
topic-data-mask-programming

Data mask programming patterns
scalar-type-predicates

Scalar type predicates
vec_poke_n

Poke values into a vector
missing_arg

Generate or handle a missing argument
ns_env

Get the namespace of a package
is_named

Is object named?
hash

Hashing
obj_address

Address of an R object
set_expr

Set and get an expression
UQ

Deprecated UQ() and UQS() operators
dev-notes-dots

Development notes - dots.R
global_entrace

Entrace unexpected errors
local_use_cli

Use cli to format error messages
topic-double-evaluation

The double evaluation problem
is_empty

Is object an empty vector or NULL?
topic-data-mask

What is data-masking and why do I need {{?
set_attrs

Add attributes to an object
new_quosures

Create a list of quosures
ns_registry_env

Return the namespace registry env
qq_show

Show injected expression
is_condition

Is object a condition?
abort

Signal an error, warning, or message
parse_expr

Parse R code
is_environment

Is object an environment?
last_error

Last abort() error
is_symbol

Is object a symbol?
local_bindings

Temporarily change bindings of an environment
seq2

Increasing sequence of integers in an interval
local_error_call

Set local error call in an execution environment
new-vector

Create vectors matching a given length
new_quosure

Create a quosure from components
topic-inject

Injecting with !!, !!!, and glue syntax
topic-error-call

Including function calls in error messages
on_load

Run expressions on load
splice-operator

Splice operator !!!
as_environment

Coerce to an environment
rlang_error

Errors of class rlang_error
new_call

Create a new call from components
is_interactive

Is R running interactively?
op-get-attr

Infix attribute accessor and setter
call_name

Extract function name or namespace of a call
zap_srcref

Zap source references
splice

Splice values at dots collection time
prim_name

Name of a primitive function
quo_label

Format quosures for printing or labelling
call_standardise

Standardise a call
check_dots_used

Check that all dots have been used
lang

Create a call
is_weakref

Is object a weak reference?
set_names

Set names of a vector
with_handlers

Establish handlers on the stack
topic-inject-out-of-context

What happens if I use injection operators out of context?
friendly_type

Format a type for error messages
op-na-default

Replace missing values
topic-error-chaining

Including contextual information with error chains
trace_back

Capture a backtrace
scoped_interactive

Deprecated scoped_ functions
f_text

Turn RHS of formula into a string or label
env_name

Label of an environment
search_envs

Search path environments
topic-defuse

Defusing R expressions
with_env

Evaluate an expression within a given environment
env_names

Names and numbers of symbols bound in an environment
format_error_call

Validate and format a function call for use in error messages
topic-condition-customisation

Customising condition messages
topic-quosure

What are quosures and when are they needed?
faq-options

Global options for rlang
is_namespace

Is an object a namespace environment?
stack

Get properties of the current or caller frame
interrupt

Simulate interrupt condition
try_fetch

Try an expression with condition handlers
wref_key

Get key/value from a weak reference object
new_formula

Create a formula
topic-data-mask-ambiguity

The data mask ambiguity
scoped_env

Deprecated scoped functions
new_function

Create a function
op-null-default

Default value for NULL
pairlist2

Collect dynamic dots in a pairlist
quo_squash

Squash a quosure
zap

Create zap objects
stack-deprecated

Call stack information
topic-condition-formatting

Formatting messages with cli
type-predicates

Type predicates