Learn R Programming

⚠️There's a newer version (1.1.4) of this package.Take me there.

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,820,374

Version

1.1.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

January 10th, 2024

Functions in rlang (1.1.3)

are_na

Test for missing values
args_dots_used

Helper for consistent documentation of used dots
abort

Signal an error, warning, or message
args_error_context

Documentation anchor for error arguments
as_function

Convert to function
args_dots_empty

Helper for consistent documentation of empty dots
embrace-operator

Embrace operator {{
call_args

Extract arguments from a call
as_box

Convert object to a box
arg_match

Match an argument to a character vector
call_inspect

Inspect a call
env

Create a new environment
as_closure

Transform to a closure
UQ

Deprecated UQ() and UQS() operators
as_utf8_character

Coerce to a character vector and attempt encoding conversion
args_data_masking

Argument type: data-masking
call2

Create a call
dots_n

How many arguments are currently forwarded in dots?
child_env

Create a child environment
enquo

Defuse function arguments
as_name

Extract names from symbols
empty_env

Get the empty environment
as_data_mask

Create a data mask
dots_splice

Splice lists
call_match

Match supplied arguments to function definition
as_environment

Coerce to an environment
check_dots_empty0

Check that dots are empty (low level variant)
as_label

Create a default name for an R object
cnd_message

Build an error message from parts
as_string

Cast symbol to string
check_dots_used

Check that all dots have been used
bare-type-predicates

Bare type predicates
check_dots_empty

Check that dots are empty
env_clone

Clone or coalesce an environment
call_fn

Extract function from a call
caller_arg

Find the caller argument for error messages
defusing-advanced

Advanced defusal operators
cnd

Create a condition object
done

Box a final value for early termination
cnd_inherits

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

Modify the arguments of a call
eval_bare

Evaluate an expression in an environment
dyn-dots

Dynamic dots features
env_names

Names and numbers of symbols bound in an environment
catch_cnd

Catch a condition
cnd_muffle

Muffle a condition
env_parent

Get parent environments
dev-notes-dots

Development notes - dots.R
env_bury

Mask bindings by defining symbols deeper in a scope
check_dots_unnamed

Check that all dots are unnamed
env_bind

Bind symbols to objects in an environment
global_handle

Register default global handlers
env_binding_lock

Lock or unlock environment bindings
chr_unserialise_unicode

Translate unicode points to UTF-8
dot-data

.data and .env pronouns
call_name

Extract function name or namespace of a call
is_expression

Is an object an expression?
env_cache

Cache a value in an environment
env_depth

Depth of an environment chain
global_entrace

Entrace unexpected errors
dots_values

Evaluate dots with preliminary splicing
env_browse

Browse environments
expr_print

Print an expression
env_get

Get an object in an environment
env_is_user_facing

Is frame environment user facing?
expr_label

Turn an expression to a label
box

Box a value
is_symbol

Is object a symbol?
env_lock

Lock an environment
bytes-class

Human readable memory sizes
fn_env

Return the closure environment of a function
inherits_any

Does an object inherit from a set of classes?
entrace

Add backtrace from error handler
env_inherits

Does environment inherit from another environment?
englue

Defuse function arguments with glue
env_unlock

Unlock an environment
duplicate

Duplicate an R object
fn_body

Get or set function body
env_poke

Poke an object in an environment
exec

Execute a function
env_has

Does an environment have or see bindings?
cnd_signal

Signal a condition object
check_exclusive

Check that arguments are mutually exclusive
is_function

Is object a function?
is_copyable

Is an object copyable?
exprs_auto_name

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

Evaluate an expression with quosures and pronoun support
check_required

Check that argument is supplied
call_standardise

Standardise a call
env_print

Pretty-print an environment
flatten

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

What type is a condition?
get_env

Get or set the environment of an object
expr

Defuse an R expression
invoke

Invoke a function with a list of arguments
ffi_standalone_types_check

Internal API for standalone-types-check
env_unbind

Remove bindings from an environment
inject

Inject objects in an R expression
last_warnings

Display last messages and warnings
has_name

Does an object have an element with this name?
f_rhs

Get or set formula components
global_prompt_install

Prompt user to install missing packages
env_name

Label of an environment
is_installed

Are packages installed in any of the libraries?
f_text

Turn RHS of formula into a string or label
missing

Missing values
expr_interp

Process unquote operators in a captured expression
new_node

Helpers for pairlist and language nodes
is_empty

Is object an empty vector or NULL?
format_error_call

Validate and format a function call for use in error messages
injection-operator

Injection operator !!
hash

Hashing
is_integerish

Is a vector integer-like?
faq-options

Global options for rlang
is_environment

Is object an environment?
env_binding_are_active

What kind of environment binding?
is_call

Is object a call?
local_error_call

Set local error call in an execution environment
interrupt

Simulate interrupt condition
friendly_type

Format a type for error messages
is_dictionaryish

Is a vector uniquely named?
names2

Get names of a vector
last_error

Last abort() error
is_formula

Is object a formula?
local_bindings

Temporarily change bindings of an environment
is_interactive

Is R running interactively?
new_quosures

Create a list of quosures
names_inform_repair

Inform about name repair
list2

Collect dynamic dots in a list
op-null-default

Default value for NULL
lang

Create a call
rep_along

Create vectors matching the length of a given vector
is_reference

Is an object referencing another?
fn_fmls

Extract arguments from a function
format_error_bullets

Format bullets for error messages
new_weakref

Create a weak reference
scoped_interactive

Deprecated scoped_ functions
new_function

Create a function
seq2

Increasing sequence of integers in an interval
is_condition

Is object a condition?
op-get-attr

Infix attribute accessor and setter
is_callable

Is an object callable?
rlang_error

Errors of class rlang_error
is_lang

Is object a call?
is_named

Is object named?
glue-operators

Name injection with "{" and "{{"
return_from

Jump to or from a frame
missing_arg

Generate or handle a missing argument
set_attrs

Add attributes to an object
qq_show

Show injected expression
scalar-type-predicates

Scalar type predicates
new_quosure

Create a quosure from components
pairlist2

Collect dynamic dots in a pairlist
parse_expr

Parse R code
scoped_env

Deprecated scoped functions
op-na-default

Replace missing values
rlib_trace_spec

Backtrace specification
set_names

Set names of a vector
quo_expr

Squash a quosure
has_length

How long is an object?
set_expr

Set and get an expression
local_options

Change global options
local_use_cli

Use cli to format error messages
new-vector

Create vectors matching a given length
is_namespace

Is an object a namespace environment?
is_true

Is object identical to TRUE or FALSE?
is_weakref

Is object a weak reference?
new_call

Create a new call from components
sym

Create a symbol or list of symbols
is_pairlist

Is object a node or pairlist?
search_envs

Search path environments
prim_name

Name of a primitive function
quosure-tools

Quosure getters, setters and predicates
new_formula

Create a formula
ns_registry_env

Return the namespace registry env
raw_deparse_str

Serialize a raw vector to a string
on_load

Run expressions on load
rlang_backtrace_on_error

Display backtrace on error
splice-operator

Splice operator !!!
rlang-package

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

Address of an R object
ns_env

Get the namespace of a package
string

Create a string
quo_label

Format quosures for printing or labelling
topic-condition-customisation

Customising condition messages
switch_type

Dispatch on base types
splice

Splice values at dots collection time
wref_key

Get key/value from a weak reference object
stack

Get properties of the current or caller frame
try_fetch

Try an expression with condition handlers
quo_squash

Squash a quosure
type-predicates

Type predicates
stack-deprecated

Call stack information
topic-embrace-constants

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

Create zap objects
topic-multiple-columns

Taking multiple columns without ...
topic-embrace-non-args

Does {{ work on regular objects?
topic-condition-formatting

Formatting messages with cli
topic-inject-out-of-context

What happens if I use injection operators out of context?
topic-data-mask-programming

Data mask programming patterns
topic-error-chaining

Including contextual information with error chains
topic-double-evaluation

The double evaluation problem
topic-metaprogramming

Metaprogramming patterns
topic-defuse

Defusing R expressions
vec_poke_n

Poke values into a vector
trace_back

Capture a backtrace
topic-quosure

What are quosures and when are they needed?
topic-data-mask

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

Base type of an object
topic-error-call

Including function calls in error messages
topic-inject

Injecting with !!, !!!, and glue syntax
vector-coercion

Coerce an object to a base type
vector-construction

Create vectors
zap_srcref

Zap source references
topic-data-mask-ambiguity

The data mask ambiguity
with_env

Evaluate an expression within a given environment
with_handlers

Establish handlers on the stack