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,956,217

Version

1.0.6

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

September 24th, 2022

Functions in rlang (1.0.6)

abort

Signal an error, warning, or message
args_error_context

Documentation anchor for error arguments
as_closure

Transform to a closure
UQ

Deprecated UQ() and UQS() operators
as_data_mask

Create a data mask
are_na

Test for missing values
bare-type-predicates

Bare type predicates
as_string

Cast symbol to string
args_dots_empty

Helper for consistent documentation of empty dots
args_dots_used

Helper for consistent documentation of used dots
as_utf8_character

Coerce to a character vector and attempt encoding conversion
as_box

Convert object to a box
as_function

Convert to function
as_environment

Coerce to an environment
as_label

Create a default name for an R object
box

Box a value
bytes-class

Human readable memory sizes
arg_match

Match an argument to a character vector
call2

Create a call
as_name

Extract names from symbols
call_args

Extract arguments from a call
call_inspect

Inspect a call
catch_cnd

Catch a condition
call_fn

Extract function from a call
check_dots_empty

Check that dots are empty
check_dots_empty0

Check that dots are empty (low level variant)
caller_arg

Find the caller argument for error messages
check_dots_unnamed

Check that all dots are unnamed
call_modify

Modify the arguments of a call
call_standardise

Standardise a call
call_match

Match supplied arguments to function definition
check_dots_used

Check that all dots have been used
check_exclusive

Check that arguments are mutually exclusive
cnd

Create a condition object
cnd_type

What type is a condition?
cnd_signal

Signal a condition object
duplicate

Duplicate an R object
dyn-dots

Dynamic dots features
dots_values

Evaluate dots with preliminary splicing
cnd_inherits

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

How many arguments are currently forwarded in dots?
cnd_message

Build an error message from parts
defusing-advanced

Advanced defusal operators
dev-notes-dots

Development notes - dots.R
entrace

Add backtrace from error handler
env

Create a new environment
env_cache

Cache a value in an environment
env_bury

Mask bindings by defining symbols deeper in a scope
check_required

Check that argument is supplied
chr_unserialise_unicode

Translate unicode points to UTF-8
call_name

Extract function name or namespace of a call
env_bind

Bind symbols to objects in an environment
cnd_muffle

Muffle a condition
env_name

Label of an environment
env_parent

Get parent environments
env_clone

Clone or coalesce an environment
env_binding_are_active

What kind of environment binding?
env_binding_lock

Lock or unlock environment bindings
env_browse

Browse environments
eval_tidy

Evaluate an expression with quosures and pronoun support
done

Box a final value for early termination
env_depth

Depth of an environment chain
env_poke

Poke an object in an environment
dot-data

.data and .env pronouns
expr_label

Turn an expression to a label
expr_print

Print an expression
global_prompt_install

Prompt user to install missing packages
env_names

Names and numbers of symbols bound in an environment
glue-operators

Name injection with "{" and "{{"
exec

Execute a function
englue

Defuse function arguments with glue
inject

Inject objects in an R expression
embrace-operator

Embrace operator {{
env_has

Does an environment have or see bindings?
env_print

Pretty-print an environment
env_get

Get an object in an environment
empty_env

Get the empty environment
env_unbind

Remove bindings from an environment
expr

Defuse an R expression
has_name

Does an object have an element with this name?
hash

Hashing
has_length

How long is an object?
inherits_any

Does an object inherit from a set of classes?
flatten

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

Ensure that all elements of a list of expressions are named
injection-operator

Injection operator !!
f_rhs

Get or set formula components
is_weakref

Is object a weak reference?
is_dictionaryish

Is a vector uniquely named?
is_empty

Is object an empty vector or NULL?
is_function

Is object a function?
is_formula

Is object a formula?
lang

Create a call
env_inherits

Does environment inherit from another environment?
fn_body

Get or set function body
enquo

Defuse function arguments
is_call

Is object a call?
is_callable

Is an object callable?
is_installed

Are packages installed in any of the libraries?
expr_interp

Process unquote operators in a captured expression
local_use_cli

Use cli to format error messages
list2

Collect dynamic dots in a list
f_text

Turn RHS of formula into a string or label
faq-options

Global options for rlang
local_bindings

Temporarily change bindings of an environment
missing

Missing values
eval_bare

Evaluate an expression in an environment
env_lock

Lock an environment
env_unlock

Unlock an environment
format_error_bullets

Format bullets for error messages
format_error_call

Validate and format a function call for use in error messages
is_integerish

Is a vector integer-like?
is_pairlist

Is object a node or pairlist?
is_condition

Is object a condition?
friendly_type

Format a type for error messages
is_environment

Is object an environment?
is_expression

Is an object an expression?
is_copyable

Is an object copyable?
is_named

Is object named?
fn_env

Return the closure environment of a function
is_namespace

Is an object a namespace environment?
new_weakref

Create a weak reference
ns_env

Get the namespace of a package
is_reference

Is an object referencing another?
obj_address

Address of an R object
ns_registry_env

Return the namespace registry env
local_error_call

Set local error call in an execution environment
pairlist2

Collect dynamic dots in a pairlist
get_env

Get or set the environment of an object
is_lang

Is object a call?
fn_fmls

Extract arguments from a function
is_interactive

Is R running interactively?
global_handle

Register default global handlers
interrupt

Simulate interrupt condition
global_entrace

Entrace unexpected errors
parse_expr

Parse R code
last_error

Last abort() error
last_warnings

Display last warnings
scalar-type-predicates

Scalar type predicates
prim_name

Name of a primitive function
qq_show

Show injected expression
rlib_trace_spec

Backtrace specification
search_envs

Search path environments
names_inform_repair

Inform about name repair
topic-data-mask-ambiguity

The data mask ambiguity
rlang_backtrace_on_error

Display backtrace on error
seq2

Increasing sequence of integers in an interval
topic-data-mask

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

Defusing R expressions
new-vector

Create vectors matching a given length
invoke

Invoke a function with a list of arguments
new_call

Create a new call from components
is_symbol

Is object a symbol?
new_formula

Create a formula
rlang_error

Errors of class rlang_error
set_attrs

Add attributes to an object
names2

Get names of a vector
is_true

Is object identical to TRUE or FALSE?
new_function

Create a function
missing_arg

Generate or handle a missing argument
quo_expr

Squash a quosure
topic-data-mask-programming

Data mask programming patterns
topic-inject

Injecting with !!, !!!, and glue syntax
local_options

Change global options
topic-metaprogramming

Metaprogramming patterns
new_node

Helpers for pairlist and language nodes
op-get-attr

Infix attribute accessor and setter
on_load

Run expressions on load
new_quosure

Create a quosure from components
quo_label

Format quosures for printing or labelling
return_from

Jump to or from a frame
op-null-default

Default value for NULL
raw_deparse_str

Serialize a raw vector to a string
new_quosures

Create a list of quosures
op-na-default

Replace missing values
rep_along

Create vectors matching the length of a given vector
topic-multiple-columns

Taking multiple columns without ...
quo_squash

Squash a quosure
scoped_env

Deprecated scoped functions
scoped_interactive

Deprecated scoped_ functions
type-predicates

Type predicates
topic-quosure

What are quosures and when are they needed?
type_of

Base type of an object
quosure-tools

Quosure getters, setters and predicates
set_names

Set names of a vector
splice-operator

Splice operator !!!
rlang-package

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

Poke values into a vector
wref_key

Get key/value from a weak reference object
vector-coercion

Coerce an object to a base type
set_expr

Set and get an expression
sym

Create a symbol or list of symbols
switch_type

Dispatch on base types
splice

Splice lists
topic-error-call

Including function calls in error messages
topic-embrace-non-args

Does {{ work on regular objects?
stack-deprecated

Call stack information
topic-condition-customisation

Customising condition messages
zap

Create zap objects
stack

Get properties of the current or caller frame
string

Create a string
topic-error-chaining

Including contextual information with error chains
topic-condition-formatting

Formatting messages with cli
zap_srcref

Zap source references
with_handlers

Establish handlers on the stack
with_env

Evaluate an expression within a given environment
topic-inject-out-of-context

What happens if I use injection operators out of context?
vector-construction

Create vectors
topic-embrace-constants

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

Capture a backtrace
topic-double-evaluation

The double evaluation problem
vector-old-ctors

Retired vector construction by length
try_fetch

Try an expression with condition handlers