rlang/ 0000755 0001762 0000144 00000000000 14176703326 011366 5 ustar ligges users rlang/NAMESPACE 0000644 0001762 0000144 00000026242 14176517033 012611 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method("$",rlang_ctxt_pronoun)
S3method("$",rlang_data_pronoun)
S3method("$",rlang_fake_data_pronoun)
S3method("$<-",quosures)
S3method("$<-",rlang_ctxt_pronoun)
S3method("$<-",rlang_data_pronoun)
S3method("[","rlang:::list_of_conditions")
S3method("[",quosure)
S3method("[",quosures)
S3method("[",rlang_ctxt_pronoun)
S3method("[",rlang_data_pronoun)
S3method("[",rlang_envs)
S3method("[",rlib_bytes)
S3method("[<-",quosures)
S3method("[[",quosure)
S3method("[[",rlang_ctxt_pronoun)
S3method("[[",rlang_data_pronoun)
S3method("[[",rlang_fake_data_pronoun)
S3method("[[",rlib_bytes)
S3method("[[<-",quosures)
S3method("[[<-",rlang_ctxt_pronoun)
S3method("[[<-",rlang_data_pronoun)
S3method(Math,quosure)
S3method(Ops,quosure)
S3method(Ops,rlib_bytes)
S3method(Summary,quosure)
S3method(as.character,quosure)
S3method(as.character,rlang_error)
S3method(as.character,rlang_message)
S3method(as.character,rlang_warning)
S3method(as.character,rlib_bytes)
S3method(as.list,quosures)
S3method(as_bytes,character)
S3method(as_bytes,numeric)
S3method(as_bytes,rlib_bytes)
S3method(c,quosures)
S3method(c,rlang_envs)
S3method(cnd_body,default)
S3method(cnd_footer,default)
S3method(cnd_header,default)
S3method(cnd_header,rlib_error_package_not_found)
S3method(conditionMessage,rlang_error)
S3method(conditionMessage,rlang_message)
S3method(conditionMessage,rlang_warning)
S3method(dimnames,rlang_data_pronoun)
S3method(format,rlang_error)
S3method(format,rlang_message)
S3method(format,rlang_trace)
S3method(format,rlang_warning)
S3method(format,rlib_bytes)
S3method(length,rlang_ctxt_pronoun)
S3method(length,rlang_data_pronoun)
S3method(length,rlang_fake_data_pronoun)
S3method(max,rlib_bytes)
S3method(mean,quosure)
S3method(median,quosure)
S3method(min,rlib_bytes)
S3method(names,rlang_ctxt_pronoun)
S3method(names,rlang_data_pronoun)
S3method(names,rlang_fake_data_pronoun)
S3method(print,"rlang:::list_of_conditions")
S3method(print,quosure)
S3method(print,quosures)
S3method(print,rlang_box_done)
S3method(print,rlang_box_splice)
S3method(print,rlang_data_pronoun)
S3method(print,rlang_dict)
S3method(print,rlang_dyn_array)
S3method(print,rlang_envs)
S3method(print,rlang_error)
S3method(print,rlang_fake_data_pronoun)
S3method(print,rlang_lambda_function)
S3method(print,rlang_message)
S3method(print,rlang_trace)
S3method(print,rlang_warning)
S3method(print,rlang_zap)
S3method(print,rlib_bytes)
S3method(quantile,quosure)
S3method(rlang_type_sum,Date)
S3method(rlang_type_sum,POSIXct)
S3method(rlang_type_sum,data.frame)
S3method(rlang_type_sum,default)
S3method(rlang_type_sum,difftime)
S3method(rlang_type_sum,factor)
S3method(rlang_type_sum,ordered)
S3method(str,quosure)
S3method(str,rlang_data_pronoun)
S3method(str,rlang_envs)
S3method(sum,rlib_bytes)
S3method(summary,"rlang:::list_of_conditions")
S3method(summary,rlang_error)
S3method(summary,rlang_message)
S3method(summary,rlang_trace)
S3method(summary,rlang_warning)
export("!!!")
export("!!")
export("%<~%")
export("%@%")
export("%@%<-")
export("%|%")
export("%||%")
export(":=")
export("f_env<-")
export("f_lhs<-")
export("f_rhs<-")
export("fn_body<-")
export("fn_env<-")
export("fn_fmls<-")
export("fn_fmls_names<-")
export("names2<-")
export(.data)
export(.env)
export(UQ)
export(UQS)
export(abort)
export(are_na)
export(arg_match)
export(arg_match0)
export(as_box)
export(as_box_if)
export(as_bytes)
export(as_character)
export(as_closure)
export(as_complex)
export(as_data_mask)
export(as_data_pronoun)
export(as_double)
export(as_environment)
export(as_function)
export(as_integer)
export(as_label)
export(as_list)
export(as_logical)
export(as_name)
export(as_quosure)
export(as_quosures)
export(as_string)
export(as_utf8_character)
export(base_env)
export(bytes)
export(call2)
export(call_args)
export(call_args_names)
export(call_fn)
export(call_inspect)
export(call_match)
export(call_modify)
export(call_name)
export(call_ns)
export(call_standardise)
export(caller_arg)
export(caller_call)
export(caller_env)
export(caller_fn)
export(calling)
export(catch_cnd)
export(check_dots_empty)
export(check_dots_empty0)
export(check_dots_unnamed)
export(check_dots_used)
export(check_exclusive)
export(check_installed)
export(check_required)
export(child_env)
export(chr)
export(chr_unserialise_unicode)
export(cnd)
export(cnd_body)
export(cnd_entrace)
export(cnd_footer)
export(cnd_header)
export(cnd_inherits)
export(cnd_message)
export(cnd_muffle)
export(cnd_signal)
export(cnd_type)
export(coerce_class)
export(coerce_type)
export(cpl)
export(ctxt_frame)
export(current_call)
export(current_env)
export(current_fn)
export(data_sym)
export(data_syms)
export(dbl)
export(done)
export(dots_list)
export(dots_n)
export(dots_splice)
export(dots_values)
export(duplicate)
export(empty_env)
export(enexpr)
export(enexprs)
export(englue)
export(enquo)
export(enquo0)
export(enquos)
export(enquos0)
export(ensym)
export(ensyms)
export(entrace)
export(env)
export(env_bind)
export(env_bind_active)
export(env_bind_lazy)
export(env_binding_are_active)
export(env_binding_are_lazy)
export(env_binding_are_locked)
export(env_binding_lock)
export(env_binding_unlock)
export(env_browse)
export(env_bury)
export(env_cache)
export(env_clone)
export(env_depth)
export(env_get)
export(env_get_list)
export(env_has)
export(env_inherits)
export(env_is_browsed)
export(env_is_locked)
export(env_label)
export(env_length)
export(env_lock)
export(env_name)
export(env_names)
export(env_parent)
export(env_parents)
export(env_poke)
export(env_poke_parent)
export(env_print)
export(env_tail)
export(env_unbind)
export(env_unlock)
export(error_cnd)
export(eval_bare)
export(eval_tidy)
export(exec)
export(exiting)
export(expr)
export(expr_deparse)
export(expr_interp)
export(expr_label)
export(expr_name)
export(expr_print)
export(expr_text)
export(exprs)
export(exprs_auto_name)
export(f_env)
export(f_label)
export(f_lhs)
export(f_name)
export(f_rhs)
export(f_text)
export(flatten)
export(flatten_chr)
export(flatten_cpl)
export(flatten_dbl)
export(flatten_if)
export(flatten_int)
export(flatten_lgl)
export(flatten_raw)
export(fn_body)
export(fn_env)
export(fn_fmls)
export(fn_fmls_names)
export(fn_fmls_syms)
export(format_error_bullets)
export(format_error_call)
export(frame_call)
export(frame_fn)
export(friendly_type)
export(get_env)
export(get_expr)
export(global_entrace)
export(global_env)
export(global_frame)
export(global_handle)
export(global_prompt_install)
export(has_length)
export(has_name)
export(hash)
export(hash_file)
export(have_name)
export(inform)
export(inherits_all)
export(inherits_any)
export(inherits_only)
export(inject)
export(int)
export(int_along)
export(interrupt)
export(invoke)
export(is_atomic)
export(is_attached)
export(is_bare_atomic)
export(is_bare_bytes)
export(is_bare_character)
export(is_bare_complex)
export(is_bare_double)
export(is_bare_environment)
export(is_bare_formula)
export(is_bare_integer)
export(is_bare_integerish)
export(is_bare_list)
export(is_bare_logical)
export(is_bare_numeric)
export(is_bare_raw)
export(is_bare_string)
export(is_bare_vector)
export(is_bool)
export(is_box)
export(is_bytes)
export(is_call)
export(is_call_simple)
export(is_callable)
export(is_character)
export(is_chr_na)
export(is_closure)
export(is_complex)
export(is_condition)
export(is_copyable)
export(is_cpl_na)
export(is_dbl_na)
export(is_dictionaryish)
export(is_done_box)
export(is_double)
export(is_empty)
export(is_environment)
export(is_error)
export(is_expression)
export(is_false)
export(is_formula)
export(is_function)
export(is_installed)
export(is_int_na)
export(is_integer)
export(is_integerish)
export(is_interactive)
export(is_lambda)
export(is_lang)
export(is_lgl_na)
export(is_list)
export(is_logical)
export(is_message)
export(is_missing)
export(is_na)
export(is_named)
export(is_named2)
export(is_namespace)
export(is_node)
export(is_node_list)
export(is_null)
export(is_pairlist)
export(is_primitive)
export(is_primitive_eager)
export(is_primitive_lazy)
export(is_quosure)
export(is_quosures)
export(is_raw)
export(is_reference)
export(is_scalar_atomic)
export(is_scalar_bytes)
export(is_scalar_character)
export(is_scalar_complex)
export(is_scalar_double)
export(is_scalar_integer)
export(is_scalar_integerish)
export(is_scalar_list)
export(is_scalar_logical)
export(is_scalar_raw)
export(is_scalar_vector)
export(is_scoped)
export(is_spliced)
export(is_spliced_bare)
export(is_string)
export(is_symbol)
export(is_symbolic)
export(is_syntactic_literal)
export(is_true)
export(is_vector)
export(is_warning)
export(is_weakref)
export(is_zap)
export(lang)
export(last_error)
export(last_messages)
export(last_trace)
export(last_warnings)
export(lgl)
export(lgl_along)
export(list2)
export(ll)
export(local_bindings)
export(local_error_call)
export(local_interactive)
export(local_options)
export(local_use_cli)
export(locally)
export(maybe_missing)
export(message_cnd)
export(missing_arg)
export(na_chr)
export(na_cpl)
export(na_dbl)
export(na_int)
export(na_lgl)
export(names2)
export(names_inform_repair)
export(new_box)
export(new_call)
export(new_character)
export(new_complex)
export(new_data_mask)
export(new_double)
export(new_environment)
export(new_formula)
export(new_function)
export(new_integer)
export(new_list)
export(new_logical)
export(new_node)
export(new_quosure)
export(new_quosures)
export(new_raw)
export(new_weakref)
export(node_caar)
export(node_cadr)
export(node_car)
export(node_cdar)
export(node_cddr)
export(node_cdr)
export(node_poke_caar)
export(node_poke_cadr)
export(node_poke_car)
export(node_poke_cdar)
export(node_poke_cddr)
export(node_poke_cdr)
export(node_poke_tag)
export(node_tag)
export(ns_env)
export(ns_env_name)
export(ns_imports_env)
export(obj_address)
export(on_load)
export(on_package_load)
export(pairlist2)
export(parse_bytes)
export(parse_expr)
export(parse_exprs)
export(parse_quo)
export(parse_quos)
export(peek_option)
export(peek_options)
export(pkg_env)
export(pkg_env_name)
export(prim_name)
export(push_options)
export(qq_show)
export(quo)
export(quo_expr)
export(quo_get_env)
export(quo_get_expr)
export(quo_is_call)
export(quo_is_missing)
export(quo_is_null)
export(quo_is_symbol)
export(quo_is_symbolic)
export(quo_label)
export(quo_name)
export(quo_set_env)
export(quo_set_expr)
export(quo_squash)
export(quo_text)
export(quos)
export(quos_auto_name)
export(raw_deparse_str)
export(rep_along)
export(rep_named)
export(return_from)
export(run_on_load)
export(scoped_bindings)
export(scoped_env)
export(scoped_interactive)
export(scoped_options)
export(search_env)
export(search_envs)
export(seq2)
export(seq2_along)
export(set_attrs)
export(set_env)
export(set_expr)
export(set_names)
export(signal)
export(splice)
export(squash)
export(squash_chr)
export(squash_cpl)
export(squash_dbl)
export(squash_if)
export(squash_int)
export(squash_lgl)
export(squash_raw)
export(string)
export(switch_class)
export(switch_type)
export(sym)
export(syms)
export(trace_back)
export(trace_length)
export(try_fetch)
export(type_of)
export(unbox)
export(vec_poke_n)
export(vec_poke_range)
export(warn)
export(warning_cnd)
export(with_bindings)
export(with_env)
export(with_handlers)
export(with_interactive)
export(with_options)
export(wref_key)
export(wref_value)
export(zap)
export(zap_srcref)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(utils,adist)
importFrom(utils,str)
useDynLib(rlang, .registration = TRUE)
rlang/LICENSE.note 0000644 0001762 0000144 00000003315 14127057575 013345 0 ustar ligges users The implementation of `hash()` uses the xxHash library from Yann Collet, which
is released under the BSD 2-Clause license. This library has been embedded into
rlang, without modification, in `src/internal/xxhash/`. A copy of the
BSD 2-Clause license is provided below.
BSD 2-Clause License -----------------------------------------------------------
xxHash Library
Copyright (c) 2012-2020 Yann Collet
All rights reserved.
BSD 2-Clause License (https://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
rlang/LICENSE 0000644 0001762 0000144 00000000053 14127057575 012375 0 ustar ligges users YEAR: 2020
COPYRIGHT HOLDER: rlang authors
rlang/README.md 0000644 0001762 0000144 00000006401 14175213516 012642 0 ustar ligges users rlang
=======================================================
[](https://github.com/r-lib/rlang/actions)
[](https://app.codecov.io/gh/r-lib/rlang?branch=main)
[](https://lifecycle.r-lib.org/articles/stages.html)
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](https://rlang.r-lib.org/reference/topic-data-mask.html) framework used in tidyverse packages like dplyr and ggplot2. As a user, you will encounter the embracing operator [`{{`](https://rlang.r-lib.org/reference/embrace-operator.html) and name injection with the [glue](https://glue.tidyverse.org/) operators [`"{"`](https://rlang.r-lib.org/reference/glue-operators.html) and [`"{{"`](https://rlang.r-lib.org/reference/glue-operators.html).
* __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](https://rlang.r-lib.org/reference/dyn-dots.html), e.g. `list2()`. These dots support splicing with [`!!!`](https://rlang.r-lib.org/reference/splice-operator.html) and name injection with the [glue](https://glue.tidyverse.org/) operators [`"{"`](https://rlang.r-lib.org/reference/glue-operators.html) and [`"{{"`](https://rlang.r-lib.org/reference/glue-operators.html).
## 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:
```r
install.packages("rlang")
```
Or install the development version from GitHub with:
```r
# 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](https://rlang.r-lib.org/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
rlang/man/ 0000755 0001762 0000144 00000000000 14176531477 012147 5 ustar ligges users rlang/man/prim_name.Rd 0000644 0001762 0000144 00000000516 14127057575 014405 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{prim_name}
\alias{prim_name}
\title{Name of a primitive function}
\usage{
prim_name(prim)
}
\arguments{
\item{prim}{A primitive function such as \code{\link[base:c]{base::c()}}.}
}
\description{
Name of a primitive function
}
\keyword{internal}
rlang/man/hash.Rd 0000644 0001762 0000144 00000002716 14175213516 013355 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/hash.R
\name{hash}
\alias{hash}
\alias{hash_file}
\title{Hashing}
\usage{
hash(x)
hash_file(path)
}
\arguments{
\item{x}{An object.}
\item{path}{A character vector of paths to the files to be hashed.}
}
\value{
\itemize{
\item For \code{hash()}, a single character string containing the hash.
\item For \code{hash_file()}, a character vector containing one hash per file.
}
}
\description{
\itemize{
\item \code{hash()} hashes an arbitrary R object.
\item \code{hash_file()} hashes the data contained in a file.
}
The generated hash is guaranteed to be reproducible across platforms that
have the same endianness and are using the same R version.
}
\details{
These hashers use the XXH128 hash algorithm of the xxHash library, which
generates a 128-bit hash. Both are implemented as streaming hashes, which
generate the hash with minimal extra memory usage.
For \code{hash()}, objects are converted to binary using R's native serialization
tools. On R >= 3.5.0, serialization version 3 is used, otherwise version 2 is
used. See \code{\link[=serialize]{serialize()}} for more information about the serialization version.
}
\examples{
hash(c(1, 2, 3))
hash(mtcars)
authors <- file.path(R.home("doc"), "AUTHORS")
copying <- file.path(R.home("doc"), "COPYING")
hashes <- hash_file(c(authors, copying))
hashes
# If you need a single hash for multiple files,
# hash the result of `hash_file()`
hash(hashes)
}
rlang/man/zap_srcref.Rd 0000644 0001762 0000144 00000001534 14127057575 014575 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/attr.R
\name{zap_srcref}
\alias{zap_srcref}
\title{Zap source references}
\usage{
zap_srcref(x)
}
\arguments{
\item{x}{An R object. Functions and calls are walked recursively.}
}
\description{
There are a number of situations where R creates source references:
\itemize{
\item Reading R code from a file with \code{source()} and \code{parse()} might save
source references inside calls to \code{function} and \verb{\{}.
\item \code{\link[=sys.call]{sys.call()}} includes a source reference if possible.
\item Creating a closure stores the source reference from the call to
\code{function}, if any.
}
These source references take up space and might cause a number of
issues. \code{zap_srcref()} recursively walks through expressions and
functions to remove all source references.
}
rlang/man/scoped_interactive.Rd 0000644 0001762 0000144 00000002745 14175213516 016306 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{scoped_interactive}
\alias{scoped_interactive}
\alias{scoped_options}
\alias{scoped_bindings}
\title{Deprecated \code{scoped_} functions}
\usage{
scoped_interactive(value = TRUE, frame = caller_env())
scoped_options(..., .frame = caller_env())
scoped_bindings(..., .env = .frame, .frame = caller_env())
}
\arguments{
\item{value}{A single \code{TRUE} or \code{FALSE}. This overrides the return
value of \code{is_interactive()}.}
\item{frame}{The environment of a running function which defines
the scope of the temporary options. When the function returns,
the options are reset to their original values.}
\item{...}{For \code{local_options()} and \code{push_options()}, named
values defining new option values. For \code{peek_options()}, strings
or character vectors of option names.}
\item{.frame}{The environment of a running function which defines
the scope of the temporary options. When the function returns,
the options are reset to their original values.}
\item{.env}{An environment.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Deprecated as of rlang 0.4.2. Use \code{\link[=local_interactive]{local_interactive()}},
\code{\link[=local_options]{local_options()}}, or \code{\link[=local_bindings]{local_bindings()}} instead.
}
\keyword{internal}
rlang/man/env_inherits.Rd 0000644 0001762 0000144 00000000655 14127057575 015137 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{env_inherits}
\alias{env_inherits}
\title{Does environment inherit from another environment?}
\usage{
env_inherits(env, ancestor)
}
\arguments{
\item{env}{An environment.}
\item{ancestor}{Another environment from which \code{x} might inherit.}
}
\description{
This returns \code{TRUE} if \code{x} has \code{ancestor} among its parents.
}
rlang/man/f_text.Rd 0000644 0001762 0000144 00000001320 14127057575 013721 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formula.R
\name{f_text}
\alias{f_text}
\alias{f_name}
\alias{f_label}
\title{Turn RHS of formula into a string or label}
\usage{
f_text(x, width = 60L, nlines = Inf)
f_name(x)
f_label(x)
}
\arguments{
\item{x}{A formula.}
\item{width}{Width of each line.}
\item{nlines}{Maximum number of lines to extract.}
}
\description{
Equivalent of \code{\link[=expr_text]{expr_text()}} and \code{\link[=expr_label]{expr_label()}} for formulas.
}
\examples{
f <- ~ a + b + bc
f_text(f)
f_label(f)
# Names a quoted with ``
f_label(~ x)
# Strings are encoded
f_label(~ "a\nb")
# Long expressions are collapsed
f_label(~ foo({
1 + 2
print(x)
}))
}
rlang/man/env_binding_lock.Rd 0000644 0001762 0000144 00000003204 14175213516 015715 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_binding_lock}
\alias{env_binding_lock}
\alias{env_binding_unlock}
\alias{env_binding_are_locked}
\title{Lock or unlock environment bindings}
\usage{
env_binding_lock(env, nms = NULL)
env_binding_unlock(env, nms = NULL)
env_binding_are_locked(env, nms = NULL)
}
\arguments{
\item{env}{An environment.}
\item{nms}{Names of bindings. Defaults to all bindings in \code{env}.}
}
\value{
\code{env_binding_are_unlocked()} returns a logical vector as
long as \code{nms} and named after it. \code{env_binding_lock()} and
\code{env_binding_unlock()} return the old value of
\code{env_binding_are_unlocked()} invisibly.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Locked environment bindings trigger an error when an attempt is
made to redefine the binding.
}
\examples{
# Bindings are unlocked by default:
env <- env(a = "A", b = "B")
env_binding_are_locked(env)
# But can optionally be locked:
env_binding_lock(env, "a")
env_binding_are_locked(env)
# If run, the following would now return an error because `a` is locked:
# env_bind(env, a = "foo")
# with_env(env, a <- "bar")
# Let's unlock it. Note that the return value indicate which
# bindings were locked:
were_locked <- env_binding_unlock(env)
were_locked
# Now that it is unlocked we can modify it again:
env_bind(env, a = "foo")
with_env(env, a <- "bar")
env$a
}
\seealso{
\code{\link[=env_lock]{env_lock()}} for locking an environment.
}
\keyword{internal}
rlang/man/stack-deprecated.Rd 0000644 0001762 0000144 00000001071 14175213516 015626 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{stack-deprecated}
\alias{stack-deprecated}
\alias{ctxt_frame}
\alias{global_frame}
\title{Call stack information}
\usage{
ctxt_frame(n = 1)
global_frame()
}
\arguments{
\item{n}{The number of frames to go back in the stack.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Deprecated as of rlang 0.3.0.
}
\keyword{internal}
rlang/man/env_name.Rd 0000644 0001762 0000144 00000002374 14127057575 014232 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-special.R
\name{env_name}
\alias{env_name}
\alias{env_label}
\title{Label of an environment}
\usage{
env_name(env)
env_label(env)
}
\arguments{
\item{env}{An environment.}
}
\description{
Special environments like the global environment have their own
names. \code{env_name()} returns:
\itemize{
\item "global" for the global environment.
\item "empty" for the empty environment.
\item "base" for the base package environment (the last environment on
the search path).
\item "namespace:pkg" if \code{env} is the namespace of the package "pkg".
\item The \code{name} attribute of \code{env} if it exists. This is how the
\link[=search_envs]{package environments} and the \link[=ns_imports_env]{imports environments} store their names. The name of package
environments is typically "package:pkg".
\item The empty string \code{""} otherwise.
}
\code{env_label()} is exactly like \code{env_name()} but returns the memory
address of anonymous environments as fallback.
}
\examples{
# Some environments have specific names:
env_name(global_env())
env_name(ns_env("rlang"))
# Anonymous environments don't have names but are labelled by their
# address in memory:
env_name(env())
env_label(env())
}
rlang/man/stack.Rd 0000644 0001762 0000144 00000002770 14175213516 013537 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stack.R
\name{stack}
\alias{stack}
\alias{current_call}
\alias{current_fn}
\alias{current_env}
\alias{caller_call}
\alias{caller_fn}
\alias{caller_env}
\alias{frame_call}
\alias{frame_fn}
\title{Get properties of the current or caller frame}
\usage{
current_call()
current_fn()
current_env()
caller_call(n = 1)
caller_fn(n = 1)
caller_env(n = 1)
frame_call(frame = caller_env())
frame_fn(frame = caller_env())
}
\arguments{
\item{n}{The number of callers to go back.}
\item{frame}{A frame environment of a currently running function,
as returned by \code{\link[=caller_env]{caller_env()}}. \code{NULL} is returned if the
environment does not exist on the stack.}
}
\description{
These accessors retrieve properties of frames on the call stack.
The prefix indicates for which frame a property should be accessed:
\itemize{
\item From the current frame with \code{current_} accessors.
\item From a calling frame with \code{caller_} accessors.
\item From a matching frame with \code{frame_} accessors.
}
The suffix indicates which property to retrieve:
\itemize{
\item \verb{_fn} accessors return the function running in the frame.
\item \verb{_call} accessors return the defused call with which the function
running in the frame was invoked.
\item \verb{_env} accessors return the execution environment of the function
running in the frame.
}
}
\seealso{
\code{\link[=caller_env]{caller_env()}} and \code{\link[=current_env]{current_env()}}
}
rlang/man/defusing-advanced.Rd 0000644 0001762 0000144 00000014011 14175213516 015770 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-defuse.R
\name{defusing-advanced}
\alias{defusing-advanced}
\alias{enexpr}
\alias{exprs}
\alias{enexprs}
\alias{ensym}
\alias{ensyms}
\alias{quo}
\alias{quos}
\alias{enquo0}
\alias{enquos0}
\title{Advanced defusal operators}
\usage{
enexpr(arg)
exprs(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE
)
enexprs(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
ensym(arg)
ensyms(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
quo(expr)
quos(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE
)
enquo0(arg)
enquos0(...)
}
\arguments{
\item{arg}{An unquoted argument name. The expression
supplied to that argument is defused and returned.}
\item{...}{For \code{enexprs()}, \code{ensyms()} and \code{enquos()}, names of
arguments to defuse. For \code{exprs()} and \code{quos()}, expressions
to defuse.}
\item{.named}{If \code{TRUE}, unnamed inputs are automatically named
with \code{\link[=as_label]{as_label()}}. This is equivalent to applying
\code{\link[=exprs_auto_name]{exprs_auto_name()}} on the result. If \code{FALSE}, unnamed elements
are left as is and, if fully unnamed, the list is given minimal
names (a vector of \code{""}). If \code{NULL}, fully unnamed results are
left with \code{NULL} names.}
\item{.ignore_empty}{Whether to ignore empty arguments. Can be one
of \code{"trailing"}, \code{"none"}, \code{"all"}. If \code{"trailing"}, only the
last argument is ignored if it is empty. Named arguments are not
considered empty.}
\item{.unquote_names}{Whether to treat \verb{:=} as \code{=}. Unlike \code{=}, the
\verb{:=} syntax supports \link[=glue-operators]{names injection}.}
\item{.homonyms}{How to treat arguments with the same name. The
default, \code{"keep"}, preserves these arguments. Set \code{.homonyms} to
\code{"first"} to only keep the first occurrences, to \code{"last"} to keep
the last occurrences, and to \code{"error"} to raise an informative
error and indicate what arguments have duplicated names.}
\item{.check_assign}{Whether to check for \verb{<-} calls. When \code{TRUE} a
warning recommends users to use \code{=} if they meant to match a
function parameter or wrap the \verb{<-} call in curly braces otherwise.
This ensures assignments are explicit.}
\item{expr}{An expression to defuse.}
}
\description{
These advanced operators \link[=topic-defuse]{defuse} R expressions.
\code{\link[=expr]{expr()}}, \code{\link[=enquo]{enquo()}}, and \code{\link[=enquos]{enquos()}} are sufficient for most
purposes but rlang provides these other operations, either for
completeness or because they are useful to experts.
\itemize{
\item \code{exprs()} is the plural variant of \code{expr()}. It returns a list of
expressions. It is like \code{\link[base:list]{base::alist()}} but with
\link[=nse-inject]{injection} support.
\item \code{quo()} and \code{quos()} are like \code{expr()} and \code{exprs()} but return
quosures instead of naked expressions. When you are defusing
your own local expressions (by opposition to function arguments
where non-local expressions are supplied by your users), there
is generally no need to attach the current environment in a
quosure. See \ifelse{html}{\link[=topic-quosure]{What are quosures and when are they needed?}}{\link[=topic-quosure]{What are quosures and when are they needed?}}.
\item \code{enexpr()} and \code{enexprs()} are like \code{\link[=enquo]{enquo()}} and \code{\link[=enquos]{enquos()}} but
return naked expressions instead of quosures. These operators
should very rarely be used because they lose track of the
environment of defused arguments.
\item \code{ensym()} and \code{ensyms()} are like \code{enexpr()} and \code{enexprs()} but
they throw an error when the defused expressions are not simple
symbols. They also support strings which are interpreted as
symbols. These functions are modelled on the behaviour of the
left-hand side of \code{=} and \verb{<-} where you can supply symbols and
strings interchangeably.\preformatted{"foo" <- NULL
list("foo" = NULL)
}
\item \code{enquo0} and \code{enquos0()} are like \code{enquo()} and \code{enquos()} but
without injection support. The injection operators \verb{!!}, \verb{!!!},
and \verb{\{\{} are not processed, instead they are preserved in the
defused expression. This makes it possible to defuse
expressions that potentially contain injection operators meant
for later use. The trade off is that it makes it harder for
users to inject expressions in your function. They have to
enable injection explicitly with \code{\link[=inject]{inject()}}.
None of the features of \link[=dyn-dots]{dynamic dots} are available
when defusing with \code{enquos0()}. For instance, trailing empty
arguments are not automatically trimmed.
}
}
\examples{
# `exprs()` is the plural variant of `expr()`
exprs(foo, bar, bar)
# `quo()` and `quos()` are the quosure variants of `expr()` and `exprs()`
quo(foo)
quos(foo, bar)
# `enexpr()` and `enexprs()` are the naked variants of `enquo()` and `enquos()`
my_function1 <- function(arg) enexpr(arg)
my_function2 <- function(arg, ...) enexprs(arg, ...)
my_function1(1 + 1)
my_function2(1 + 1, 10 * 2)
# `ensym()` and `ensyms()` are symbol variants of `enexpr()` and `enexprs()`
my_function3 <- function(arg) ensym(arg)
my_function4 <- function(arg, ...) ensyms(arg, ...)
# The user must supply symbols
my_function3(foo)
my_function4(foo, bar)
# Complex expressions are an error
try(my_function3(1 + 1))
try(my_function4(1 + 1, 10 * 2))
# `enquo0()` and `enquos0()` disable injection operators
automatic_injection <- function(x) enquo(x)
no_injection <- function(x) enquo0(x)
automatic_injection(foo(!!!1:3))
no_injection(foo(!!!1:3))
# Injection can still be done explicitly
inject(no_injection(foo(!!!1:3)))
}
\keyword{internal}
rlang/man/env_bind.Rd 0000644 0001762 0000144 00000013520 14175213516 014211 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_bind}
\alias{env_bind}
\alias{env_bind_lazy}
\alias{env_bind_active}
\alias{\%<~\%}
\title{Bind symbols to objects in an environment}
\usage{
env_bind(.env, ...)
env_bind_lazy(.env, ..., .eval_env = caller_env())
env_bind_active(.env, ...)
lhs \%<~\% rhs
}
\arguments{
\item{.env}{An environment.}
\item{...}{<\link[=dyn-dots]{dynamic}> Named objects (\code{env_bind()}),
expressions \code{env_bind_lazy()}, or functions (\code{env_bind_active()}).
Use \code{\link[=zap]{zap()}} to remove bindings.}
\item{.eval_env}{The environment where the expressions will be
evaluated when the symbols are forced.}
\item{lhs}{The variable name to which \code{rhs} will be lazily assigned.}
\item{rhs}{An expression lazily evaluated and assigned to \code{lhs}.}
}
\value{
The input object \code{.env}, with its associated environment
modified in place, invisibly.
}
\description{
These functions create bindings in an environment. The bindings are
supplied through \code{...} as pairs of names and values or expressions.
\code{env_bind()} is equivalent to evaluating a \verb{<-} expression within
the given environment. This function should take care of the
majority of use cases but the other variants can be useful for
specific problems.
\itemize{
\item \code{env_bind()} takes named \emph{values} which are bound in \code{.env}.
\code{env_bind()} is equivalent to \code{\link[base:assign]{base::assign()}}.
\item \code{env_bind_active()} takes named \emph{functions} and creates active
bindings in \code{.env}. This is equivalent to
\code{\link[base:bindenv]{base::makeActiveBinding()}}. An active binding executes a
function each time it is evaluated. The arguments are passed to
\code{\link[=as_function]{as_function()}} so you can supply formulas instead of functions.
Remember that functions are scoped in their own environment.
These functions can thus refer to symbols from this enclosure
that are not actually in scope in the dynamic environment where
the active bindings are invoked. This allows creative solutions
to difficult problems (see the implementations of \code{dplyr::do()}
methods for an example).
\item \code{env_bind_lazy()} takes named \emph{expressions}. This is equivalent
to \code{\link[base:delayedAssign]{base::delayedAssign()}}. The arguments are captured with
\code{\link[=exprs]{exprs()}} (and thus support call-splicing and unquoting) and
assigned to symbols in \code{.env}. These expressions are not
evaluated immediately but lazily. Once a symbol is evaluated, the
corresponding expression is evaluated in turn and its value is
bound to the symbol (the expressions are thus evaluated only
once, if at all).
\item \verb{\%<~\%} is a shortcut for \code{env_bind_lazy()}. It works like \verb{<-}
but the RHS is evaluated lazily.
}
}
\section{Side effects}{
Since environments have reference semantics (see relevant section
in \code{\link[=env]{env()}} documentation), modifying the bindings of an environment
produces effects in all other references to that environment. In
other words, \code{env_bind()} and its variants have side effects.
Like other side-effecty functions like \code{par()} and \code{options()},
\code{env_bind()} and variants return the old values invisibly.
}
\examples{
# env_bind() is a programmatic way of assigning values to symbols
# with `<-`. We can add bindings in the current environment:
env_bind(current_env(), foo = "bar")
foo
# Or modify those bindings:
bar <- "bar"
env_bind(current_env(), bar = "BAR")
bar
# You can remove bindings by supplying zap sentinels:
env_bind(current_env(), foo = zap())
try(foo)
# Unquote-splice a named list of zaps
zaps <- rep_named(c("foo", "bar"), list(zap()))
env_bind(current_env(), !!!zaps)
try(bar)
# It is most useful to change other environments:
my_env <- env()
env_bind(my_env, foo = "foo")
my_env$foo
# A useful feature is to splice lists of named values:
vals <- list(a = 10, b = 20)
env_bind(my_env, !!!vals, c = 30)
my_env$b
my_env$c
# You can also unquote a variable referring to a symbol or a string
# as binding name:
var <- "baz"
env_bind(my_env, !!var := "BAZ")
my_env$baz
# The old values of the bindings are returned invisibly:
old <- env_bind(my_env, a = 1, b = 2, baz = "baz")
old
# You can restore the original environment state by supplying the
# old values back:
env_bind(my_env, !!!old)
# env_bind_lazy() assigns expressions lazily:
env <- env()
env_bind_lazy(env, name = { cat("forced!\n"); "value" })
# Referring to the binding will cause evaluation:
env$name
# But only once, subsequent references yield the final value:
env$name
# You can unquote expressions:
expr <- quote(message("forced!"))
env_bind_lazy(env, name = !!expr)
env$name
# By default the expressions are evaluated in the current
# environment. For instance we can create a local binding and refer
# to it, even though the variable is bound in a different
# environment:
who <- "mickey"
env_bind_lazy(env, name = paste(who, "mouse"))
env$name
# You can specify another evaluation environment with `.eval_env`:
eval_env <- env(who = "minnie")
env_bind_lazy(env, name = paste(who, "mouse"), .eval_env = eval_env)
env$name
# Or by unquoting a quosure:
quo <- local({
who <- "fievel"
quo(paste(who, "mouse"))
})
env_bind_lazy(env, name = !!quo)
env$name
# You can create active bindings with env_bind_active(). Active
# bindings execute a function each time they are evaluated:
fn <- function() {
cat("I have been called\n")
rnorm(1)
}
env <- env()
env_bind_active(env, symbol = fn)
# `fn` is executed each time `symbol` is evaluated or retrieved:
env$symbol
env$symbol
eval_bare(quote(symbol), env)
eval_bare(quote(symbol), env)
# All arguments are passed to as_function() so you can use the
# formula shortcut:
env_bind_active(env, foo = ~ runif(1))
env$foo
env$foo
}
\seealso{
\code{\link[=env_poke]{env_poke()}} for binding a single element.
}
rlang/man/call_modify.Rd 0000644 0001762 0000144 00000005632 14175213516 014714 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call_modify}
\alias{call_modify}
\title{Modify the arguments of a call}
\usage{
call_modify(
.call,
...,
.homonyms = c("keep", "first", "last", "error"),
.standardise = NULL,
.env = caller_env()
)
}
\arguments{
\item{.call}{Can be a call, a formula quoting a call in the
right-hand side, or a frame object from which to extract the call
expression.}
\item{...}{<\link[=dyn-dots]{dynamic}> Named or unnamed expressions
(constants, names or calls) used to modify the call. Use \code{\link[=zap]{zap()}}
to remove arguments. Empty arguments are preserved.}
\item{.homonyms}{How to treat arguments with the same name. The
default, \code{"keep"}, preserves these arguments. Set \code{.homonyms} to
\code{"first"} to only keep the first occurrences, to \code{"last"} to keep
the last occurrences, and to \code{"error"} to raise an informative
error and indicate what arguments have duplicated names.}
\item{.standardise, .env}{Deprecated as of rlang 0.3.0. Please
call \code{\link[=call_match]{call_match()}} manually.}
}
\value{
A quosure if \code{.call} is a quosure, a call otherwise.
}
\description{
If you are working with a user-supplied call, make sure the
arguments are standardised with \code{\link[=call_match]{call_match()}} before
modifying the call.
}
\examples{
call <- quote(mean(x, na.rm = TRUE))
# Modify an existing argument
call_modify(call, na.rm = FALSE)
call_modify(call, x = quote(y))
# Remove an argument
call_modify(call, na.rm = zap())
# Add a new argument
call_modify(call, trim = 0.1)
# Add an explicit missing argument:
call_modify(call, na.rm = )
# Supply a list of new arguments with `!!!`
newargs <- list(na.rm = NULL, trim = 0.1)
call <- call_modify(call, !!!newargs)
call
# Remove multiple arguments by splicing zaps:
newargs <- rep_named(c("na.rm", "trim"), list(zap()))
call <- call_modify(call, !!!newargs)
call
# Modify the `...` arguments as if it were a named argument:
call <- call_modify(call, ... = )
call
call <- call_modify(call, ... = zap())
call
# When you're working with a user-supplied call, standardise it
# beforehand in case it includes unmatched arguments:
user_call <- quote(matrix(x, nc = 3))
call_modify(user_call, ncol = 1)
# `call_match()` applies R's argument matching rules. Matching
# ensures you're modifying the intended argument.
user_call <- call_match(user_call, matrix)
user_call
call_modify(user_call, ncol = 1)
# By default, arguments with the same name are kept. This has
# subtle implications, for instance you can move an argument to
# last position by removing it and remapping it:
call <- quote(foo(bar = , baz))
call_modify(call, bar = NULL, bar = missing_arg())
# You can also choose to keep only the first or last homonym
# arguments:
args <- list(bar = NULL, bar = missing_arg())
call_modify(call, !!!args, .homonyms = "first")
call_modify(call, !!!args, .homonyms = "last")
}
rlang/man/zap.Rd 0000644 0001762 0000144 00000001522 14127057575 013226 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s3.R
\name{zap}
\alias{zap}
\alias{is_zap}
\title{Create zap objects}
\usage{
zap()
is_zap(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
\code{zap()} creates a sentinel object that indicates that an object
should be removed. For instance, named zaps instruct \code{\link[=env_bind]{env_bind()}}
and \code{\link[=call_modify]{call_modify()}} to remove those objects from the environment or
the call.
The advantage of zap objects is that they unambiguously signal the
intent of removing an object. Sentinels like \code{NULL} or
\code{\link[=missing_arg]{missing_arg()}} are ambiguous because they represent valid R
objects.
}
\examples{
# Create one zap object:
zap()
# Create a list of zaps:
rep(list(zap()), 3)
rep_named(c("foo", "bar"), list(zap()))
}
rlang/man/is_condition.Rd 0000644 0001762 0000144 00000000575 14175213516 015114 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd.R
\name{is_condition}
\alias{is_condition}
\alias{is_error}
\alias{is_warning}
\alias{is_message}
\title{Is object a condition?}
\usage{
is_condition(x)
is_error(x)
is_warning(x)
is_message(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
Is object a condition?
}
\keyword{internal}
rlang/man/scoped_env.Rd 0000644 0001762 0000144 00000001322 14175213516 014547 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{scoped_env}
\alias{scoped_env}
\alias{is_scoped}
\title{Deprecated \code{scoped} functions}
\usage{
scoped_env(nm)
is_scoped(nm)
}
\arguments{
\item{nm}{The name of an environment attached to the search
path. Call \code{\link[base:search]{base::search()}} to see what is currently on the path.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
These functions are deprecated as of rlang 0.3.0. Please use
\code{\link[=is_attached]{is_attached()}} instead.
}
\keyword{internal}
rlang/man/cnd_message.Rd 0000644 0001762 0000144 00000006022 14175213516 014674 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-message.R
\name{cnd_message}
\alias{cnd_message}
\alias{cnd_header}
\alias{cnd_body}
\alias{cnd_footer}
\title{Build an error message from parts}
\usage{
cnd_message(cnd, ..., inherit = TRUE, prefix = FALSE)
cnd_header(cnd, ...)
cnd_body(cnd, ...)
cnd_footer(cnd, ...)
}
\arguments{
\item{cnd}{A condition object.}
\item{...}{Arguments passed to methods.}
\item{inherit}{Wether to include parent messages. Parent messages
are printed with a "Caused by error:" prefix, even if \code{prefix} is
\code{FALSE}.}
\item{prefix}{Whether to print the full message, including the
condition prefix (\verb{Error:}, \verb{Warning:}, \verb{Message:}, or
\verb{Condition:}). The prefix mentions the \code{call} field if present,
and the \code{srcref} info if present. If \code{cnd} has a \code{parent} field
(i.e. the condition is chained), the parent messages are included
in the message with a \verb{Caused by} prefix.}
}
\description{
\code{cnd_message()} assembles an error message from three generics:
\itemize{
\item \code{cnd_header()}
\item \code{cnd_body()}
\item \code{cnd_footer()}
}
Methods for these generics must return a character vector. The
elements are combined into a single string with a newline
separator. Bullets syntax is supported, either through rlang (see
\code{\link[=format_error_bullets]{format_error_bullets()}}), or through cli if the condition has
\code{use_cli_format} set to \code{TRUE}.
The default method for the error header returns the \code{message} field
of the condition object. The default methods for the body and
footer return the the \code{body} and \code{footer} fields if any, or empty
character vectors otherwise.
\code{cnd_message()} is automatically called by the \code{conditionMessage()}
for rlang errors, warnings, and messages. Error classes created
with \code{\link[=abort]{abort()}} only need to implement header, body or footer
methods. This provides a lot of flexibility for hierarchies of
error classes, for instance you could inherit the body of an error
message from a parent class while overriding the header and footer.
}
\section{Overriding header, body, and footer methods}{
Sometimes the contents of an error message depends on the state of
your checking routine. In that case, it can be tricky to lazily
generate error messages with \code{cnd_header()}, \code{cnd_body()}, and
\code{cnd_footer()}: you have the choice between overspecifying your
error class hierarchies with one class per state, or replicating
the type-checking control flow within the \code{cnd_body()} method. None
of these options are ideal.
A better option is to define \code{header}, \code{body}, or \code{footer} fields
in your condition object. These can be a static string, a
\link[=as_function]{lambda-formula}, or a function with the same
signature as \code{cnd_header()}, \code{cnd_body()}, or \code{cnd_footer()}. These
fields override the message generics and make it easy to generate
an error message tailored to the state in which the error was
constructed.
}
rlang/man/topic-multiple-columns.Rd 0000644 0001762 0000144 00000014375 14175213516 017063 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic-nse.R
\name{topic-multiple-columns}
\alias{topic-multiple-columns}
\title{Taking multiple columns without \code{...}}
\description{
In this guide we compare ways of taking multiple columns in a single function argument.
As a refresher (see the \link[=topic-data-mask-programming]{programming patterns} article), there are two common ways of passing arguments to \link[=topic-data-mask]{data-masking} functions. For single arguments, embrace with \ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}}:\if{html}{\out{
}}\preformatted{my_group_by <- function(data, var) \{
data \%>\% dplyr::group_by(\{\{ var \}\})
\}
my_pivot_longer <- function(data, var) \{
data \%>\% tidyr::pivot_longer(\{\{ var \}\})
\}
}\if{html}{\out{
}}
For multiple arguments in \code{...}, pass them on to functions that also take \code{...} like \code{group_by()}, or pass them within \code{c()} for functions taking tidy selection in a single argument like \code{pivot_longer()}:\if{html}{\out{
}}
But what if you want to take multiple columns in a single named argument rather than in \code{...}?
}
\section{Using tidy selections}{
The idiomatic tidyverse way of taking multiple columns in a single argument is to take a \emph{tidy selection} (see the \link[=topic-data-mask-programming]{Argument behaviours} section). In tidy selections, the syntax for passing multiple columns in a single argument is \code{c()}:\if{html}{\out{
}}
Since \verb{\{\{} inherits behaviour, this implementation of \code{my_pivot_longer()} automatically allows multiple columns passing:\if{html}{\out{
}}\preformatted{my_pivot_longer <- function(data, var) \{
data \%>\% tidyr::pivot_longer(\{\{ var \}\})
\}
mtcars \%>\% my_pivot_longer(c(am, cyl, vs))
}\if{html}{\out{
}}
For \code{group_by()}, which takes data-masked arguments, we'll use \code{across()} as a \emph{bridge} (see \link[=topic-data-mask-programming]{Bridge patterns}).\if{html}{\out{
}}\preformatted{my_group_by <- function(data, var) \{
data \%>\% dplyr::group_by(across(\{\{ var \}\}))
\}
mtcars \%>\% my_group_by(c(am, cyl, vs))
}\if{html}{\out{
}}
When embracing in tidyselect context or using \code{across()} is not possible, you might have to implement tidyselect behaviour manually with \code{tidyselect::eval_select()}.
}
\section{Using external defusal}{
To implement an argument with tidyselect behaviour, it is necessary to \link[=topic-defuse]{defuse} the argument. However defusing an argument which had historically behaved like a regular argument is a rather disruptive breaking change. This is why we could not implement tidy selections in ggplot2 facetting functions like \code{facet_grid()} and \code{facet_wrap()}.
An alternative is to use external defusal of arguments. This is what formula interfaces do for instance. A modelling function takes a formula in a regular argument and the formula defuses the user code:\if{html}{\out{
}}
Once created, the defused expressions contained in the formula are passed around like a normal argument. A similar approach was taken to update \code{facet_} functions to tidy eval. The \code{vars()} function (a simple alias to \code{\link[=quos]{quos()}}) is provided so that users can defuse their arguments externally.\if{html}{\out{
}}
You can implement this approach by simply taking a list of defused expressions as argument. This list can be passed the usual way to other functions taking such lists:\if{html}{\out{
}}
}
\section{A non-approach: Parsing lists}{
Intuitively, many programmers who want to take a list of expressions in a single argument try to defuse an argument and parse it. The user is expected to supply multiple arguments within a \code{list()} expression. When such a call is detected, the arguments are retrieved and spliced with \verb{!!!}. Otherwise, the user is assumed to have supplied a single argument which is injected with \verb{!!}. An implementation along these lines might look like this:\if{html}{\out{
}}\preformatted{my_group_by <- function(data, vars) \{
vars <- enquo(vars)
if (quo_is_call(vars, "list")) \{
expr <- quo_get_expr(vars)
env <- quo_get_env(vars)
args <- as_quosures(call_args(expr), env = env)
data \%>\% dplyr::group_by(!!!args)
\} else \{
data \%>\% dplyr::group_by(!!vars)
\}
\}
}\if{html}{\out{
}}
However this parsing approach quickly shows limits:\if{html}{\out{
}}\preformatted{mtcars \%>\% my_group_by(list2(cyl, am))
#> Error in `group_by()`: Can't add columns.
#> ℹ `..1 = list2(cyl, am)`.
#> ℹ `..1` must be size 32 or 1, not 2.
}\if{html}{\out{
}}
Also, it would be better for overall consistency of interfaces to use the tidyselect syntax \code{c()} for passing multiple columns. In general, we recommend to use either the tidyselect or the external defusal approaches.
}
\keyword{internal}
rlang/man/format_error_call.Rd 0000644 0001762 0000144 00000003404 14175213516 016121 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{format_error_call}
\alias{format_error_call}
\title{Validate and format a function call for use in error messages}
\usage{
format_error_call(call)
}
\arguments{
\item{call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\value{
Either a string formatted as code or \code{NULL} if a simple
call could not be generated.
}
\description{
\code{format_error_call()} simplifies its input to a simple call (see
section below) and formats the result as code (using cli if
available). Use this function to generate the "in" part
of an error message from a stack frame call.
If passed an environment, the corresponding \code{sys.call()} is taken
as call, unless there is a local flag (see \code{\link[=local_error_call]{local_error_call()}}).
}
\section{Details of formatting}{
\itemize{
\item The arguments of function calls are stripped.
\item Complex function calls containing inlined objects return
\code{NULL}.
\item Calls to \code{if} preserve the condition since it might be
informative. Branches are dropped.
\item Calls to operators and other special syntax are formatted using
their names rather than the potentially confusing function form.
}
}
\examples{
# Arguments are stripped
writeLines(format_error_call(quote(foo(bar, baz))))
# Returns `NULL` with complex calls such as those that contain
# inlined functions
format_error_call(call2(list))
# Operators are formatted using their names rather than in
# function call form
writeLines(format_error_call(quote(1 + 2)))
}
\keyword{internal}
rlang/man/injection-operator.Rd 0000644 0001762 0000144 00000011375 14175213516 016246 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-inject.R
\name{injection-operator}
\alias{injection-operator}
\alias{bang-bang}
\alias{!!}
\title{Injection operator \verb{!!}}
\description{
The \link[=topic-inject]{injection} operator \verb{!!} injects a value or
expression inside another expression. In other words, it modifies a
piece of code before R evaluates it.
There are two main cases for injection. You can inject constant
values to work around issues of \link[=topic-data-mask-ambiguity]{scoping ambiguity}, and you can inject \link[=topic-defuse]{defused expressions} like \link[=sym]{symbolised} column names.
}
\section{Where does \verb{!!} work?}{
\verb{!!} does not work everywhere, you can only use it within certain
special functions:
\itemize{
\item Functions taking \link[=topic-defuse]{defused} and
\link[=topic-data-mask]{data-masked} arguments.
Technically, this means function arguments defused with
\ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}} or \code{en}-prefixed operators like
\code{\link[=enquo]{enquo()}}, \code{\link[=enexpr]{enexpr()}}, etc.
\item Inside \code{\link[=inject]{inject()}}.
}
All data-masking verbs in the tidyverse support injection operators
out of the box. With base functions, you need to use \code{\link[=inject]{inject()}} to
enable \verb{!!}. Using \verb{!!} out of context may lead to incorrect
results, see \ifelse{html}{\link[=topic-inject-out-of-context]{What happens if I use injection operators out of context?}}{\link[=topic-inject-out-of-context]{What happens if I use injection operators out of context?}}.
The examples below are built around the base function \code{\link[=with]{with()}}.
Since it's not a tidyverse function we will use \code{\link[=inject]{inject()}} to enable
\verb{!!} usage.
}
\section{Injecting values}{
Data-masking functions like \code{\link[=with]{with()}} are handy because you can
refer to column names in your computations. This comes at the price
of data mask ambiguity: if you have defined an env-variable of the
same name as a data-variable, you get a name collisions. This
collision is always resolved by giving precedence to the
data-variable (it masks the env-variable):\if{html}{\out{
}}
Note that the \code{\link{.env}} pronoun is a simpler way of solving the
ambiguity. See \ifelse{html}{\link[=topic-data-mask-ambiguity]{The data mask ambiguity}}{\link[=topic-data-mask-ambiguity]{The data mask ambiguity}} for more about
this.
}
\section{Injecting expressions}{
Injection is also useful for modifying parts of a \link[=topic-defuse]{defused expression}. In the following example we use the
\link[=topic-metaprogramming]{symbolise-and-inject pattern} to
inject a column name inside a data-masked expression.\if{html}{\out{
}}
Since \code{\link[=with]{with()}} is a base function, you can't inject
\link[=topic-quosure]{quosures}, only naked symbols and calls. This
isn't a problem here because we're injecting the name of a data
frame column. If the environment is important, try injecting a
pre-computed value instead.
}
\section{When do I need \verb{!!}?}{
With tidyverse APIs, injecting expressions with \verb{!!} is no longer a
common pattern. First, the \code{\link{.env}} pronoun solves the
ambiguity problem in a more intuitive way:\if{html}{\out{
}}
Second, the embrace operator \ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}} makes the
\link[=topic-metaprogramming]{defuse-and-inject pattern} easier to
learn and use.\if{html}{\out{
}}\preformatted{my_mean <- function(data, var) \{
data \%>\% dplyr::summarise(mean(\{\{ var \}\}))
\}
# Equivalent to
my_mean <- function(data, var) \{
data \%>\% dplyr::summarise(mean(!!enquo(var)))
\}
}\if{html}{\out{
}}
\verb{!!} is a good tool to learn for advanced applications but our
hope is that it isn't needed for common data analysis cases.
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}
\item \ifelse{html}{\link[=topic-metaprogramming]{Metaprogramming patterns}}{\link[=topic-metaprogramming]{Metaprogramming patterns}}
}
}
rlang/man/f_rhs.Rd 0000644 0001762 0000144 00000001543 13351410454 013523 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formula.R
\name{f_rhs}
\alias{f_rhs}
\alias{f_rhs<-}
\alias{f_lhs}
\alias{f_lhs<-}
\alias{f_env}
\alias{f_env<-}
\title{Get or set formula components}
\usage{
f_rhs(f)
f_rhs(x) <- value
f_lhs(f)
f_lhs(x) <- value
f_env(f)
f_env(x) <- value
}
\arguments{
\item{f, x}{A formula}
\item{value}{The value to replace with.}
}
\value{
\code{f_rhs} and \code{f_lhs} return language objects (i.e. atomic
vectors of length 1, a name, or a call). \code{f_env} returns an
environment.
}
\description{
\code{f_rhs} extracts the righthand side, \code{f_lhs} extracts the lefthand
side, and \code{f_env} extracts the environment. All functions throw an
error if \code{f} is not a formula.
}
\examples{
f_rhs(~ 1 + 2 + 3)
f_rhs(~ x)
f_rhs(~ "A")
f_rhs(1 ~ 2)
f_lhs(~ y)
f_lhs(x ~ y)
f_env(~ x)
}
rlang/man/local_use_cli.Rd 0000644 0001762 0000144 00000004054 14175213516 015224 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{local_use_cli}
\alias{local_use_cli}
\title{Use cli to format error messages}
\usage{
local_use_cli(..., format = TRUE, inline = FALSE, frame = caller_env())
}
\arguments{
\item{...}{These dots are for future extensions and must be empty.}
\item{format}{Whether to use cli at print-time to format messages
and bullets.}
\item{inline}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} Whether to use
cli at throw-time to format the inline parts of a message. This
makes it possible to use cli interpolation and formatting with
\code{abort()}.}
\item{frame}{A package namespace or an environment of a running
function.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
\code{local_use_cli()} marks a package namespace or the environment of a
running function with a special flag that instructs \code{\link[=abort]{abort()}} to
use cli to format error messages. This formatting happens lazily,
at print-time, in various places:
\itemize{
\item When an unexpected error is displayed to the user.
\item When a captured error is printed in the console, for instance via
\code{\link[=last_error]{last_error()}}.
\item When \code{\link[=conditionMessage]{conditionMessage()}} is called.
}
cli formats messages and bullets with indentation and
width-wrapping to produce a polished display of messages.
}
\section{Usage}{
To use cli formatting automatically in your package:
\enumerate{
\item Make sure \code{\link[=run_on_load]{run_on_load()}} is called from your \code{.onLoad()} hook.
\item Call \code{on_load(local_use_cli())} at the top level of your namespace.
}
It is also possible to call \code{local_use_cli()} inside a running
function, in which case the flag only applies within that function.
}
\keyword{internal}
rlang/man/sym.Rd 0000644 0001762 0000144 00000004061 14175213516 013235 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sym.R
\name{sym}
\alias{sym}
\alias{syms}
\alias{data_sym}
\alias{data_syms}
\title{Create a symbol or list of symbols}
\usage{
sym(x)
syms(x)
data_sym(x)
data_syms(x)
}
\arguments{
\item{x}{For \code{sym()} and \code{data_sym()}, a string. For \code{syms()} and
\code{data_syms()}, a list of strings.}
}
\value{
For \code{sym()} and \code{syms()}, a symbol or list of symbols. For
\code{data_sym()} and \code{data_syms()}, calls of the form \code{.data$foo}.
}
\description{
Symbols are a kind of \link[=topic-defuse]{defused expression} that
represent objects in environments.
\itemize{
\item \code{sym()} and \code{syms()} take strings as input and turn them into
symbols.
\item \code{data_sym()} and \code{data_syms()} create calls of the form
\code{.data$foo} instead of symbols. Subsetting the \code{\link{.data}} pronoun
is more robust when you expect a data-variable. See
\ifelse{html}{\link[=topic-data-mask-ambiguity]{The data mask ambiguity}}{\link[=topic-data-mask-ambiguity]{The data mask ambiguity}}.
}
Only tidy eval APIs support the \code{\link{.data}} pronoun. With base R
functions, use simple symbols created with \code{sym()} or \code{syms()}.
}
\examples{
# Create a symbol
sym("cyl")
# Create a list of symbols
syms(c("cyl", "am"))
# Symbolised names refer to variables
eval(sym("cyl"), mtcars)
# Beware of scoping issues
Cyl <- "wrong"
eval(sym("Cyl"), mtcars)
# Data symbols are explicitly scoped in the data mask
try(eval_tidy(data_sym("Cyl"), mtcars))
# These can only be used with tidy eval functions
try(eval(data_sym("Cyl"), mtcars))
# The empty string returns the missing argument:
sym("")
# This way sym() and as_string() are inverse of each other:
as_string(missing_arg())
sym(as_string(missing_arg()))
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-defuse]{Defusing R expressions}}{\link[=topic-defuse]{Defusing R expressions}}
\item \ifelse{html}{\link[=topic-metaprogramming]{Metaprogramming patterns}}{\link[=topic-metaprogramming]{Metaprogramming patterns}}
}
}
rlang/man/names2.Rd 0000644 0001762 0000144 00000001725 14175213516 013616 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/attr.R
\name{names2}
\alias{names2}
\alias{names2<-}
\title{Get names of a vector}
\usage{
names2(x)
names2(x) <- value
}
\arguments{
\item{x}{A vector.}
\item{value}{New names.}
}
\description{
\code{names2()} always returns a character vector, even when an
object does not have a \code{names} attribute. In this case, it returns
a vector of empty names \code{""}. It also standardises missing names to
\code{""}.
The replacement variant \verb{names2<-} never adds \code{NA} names and
instead fills unnamed vectors with \code{""}.
}
\examples{
names2(letters)
# It also takes care of standardising missing names:
x <- set_names(1:3, c("a", NA, "b"))
names2(x)
# Replacing names with the base `names<-` function may introduce
# `NA` values when the vector is unnamed:
x <- 1:3
names(x)[1:2] <- "foo"
names(x)
# Use the `names2<-` variant to avoid this
x <- 1:3
names2(x)[1:2] <- "foo"
names(x)
}
rlang/man/is_environment.Rd 0000644 0001762 0000144 00000000614 13351410763 015462 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{is_environment}
\alias{is_environment}
\alias{is_bare_environment}
\title{Is object an environment?}
\usage{
is_environment(x)
is_bare_environment(x)
}
\arguments{
\item{x}{object to test}
}
\description{
\code{is_bare_environment()} tests whether \code{x} is an environment without a s3 or
s4 class.
}
rlang/man/call_standardise.Rd 0000644 0001762 0000144 00000003003 14175213516 015714 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{call_standardise}
\alias{call_standardise}
\title{Standardise a call}
\usage{
call_standardise(call, env = caller_env())
}
\arguments{
\item{call}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
\item{env}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\value{
A quosure if \code{call} is a quosure, a raw call otherwise.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Deprecated in rlang 0.4.11 in favour of \code{\link[=call_match]{call_match()}}.
\code{call_standardise()} was designed for call wrappers that include an
environment like formulas or quosures. The function definition was
plucked from that environment. However in practice it is rare to
use it with wrapped calls, and then it's easy to forget to supply
the environment. For these reasons, we have designed \code{\link[=call_match]{call_match()}}
as a simpler wrapper around \code{\link[=match.call]{match.call()}}.
This is essentially equivalent to \code{\link[base:match.call]{base::match.call()}}, but with
experimental handling of primitive functions.
}
\keyword{internal}
rlang/man/call_name.Rd 0000644 0001762 0000144 00000004075 14175213516 014345 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call_name}
\alias{call_name}
\alias{call_ns}
\alias{is_call_simple}
\title{Extract function name or namespace of a call}
\usage{
call_name(call)
call_ns(call)
is_call_simple(x, ns = NULL)
}
\arguments{
\item{call}{A defused call.}
\item{x}{An object to test.}
\item{ns}{Whether call is namespaced. If \code{NULL}, \code{is_call_simple()}
is insensitive to namespaces. If \code{TRUE}, \code{is_call_simple()}
detects namespaced calls. If \code{FALSE}, it detects unnamespaced
calls.}
}
\value{
The function name or namespace as a string, or \code{NULL} if
the call is not named or namespaced.
}
\description{
\code{call_name()} and \code{call_ns()} extract the function name or
namespace of \emph{simple} calls as a string. They return \code{NULL} for
complex calls.
\itemize{
\item Simple calls: \code{foo()}, \code{bar::foo()}.
\item Complex calls: \code{foo()()}, \code{bar::foo}, \code{foo$bar()}, \code{(function() NULL)()}.
}
The \code{is_call_simple()} predicate helps you determine whether a call
is simple. There are two invariants you can count on:
\enumerate{
\item If \code{is_call_simple(x)} returns \code{TRUE}, \code{call_name(x)} returns a
string. Otherwise it returns \code{NULL}.
\item If \code{is_call_simple(x, ns = TRUE)} returns \code{TRUE}, \code{call_ns()}
returns a string. Otherwise it returns \code{NULL}.
}
}
\examples{
# Is the function named?
is_call_simple(quote(foo()))
is_call_simple(quote(foo[[1]]()))
# Is the function namespaced?
is_call_simple(quote(list()), ns = TRUE)
is_call_simple(quote(base::list()), ns = TRUE)
# Extract the function name from quoted calls:
call_name(quote(foo(bar)))
call_name(quo(foo(bar)))
# Namespaced calls are correctly handled:
call_name(quote(base::matrix(baz)))
# Anonymous and subsetted functions return NULL:
call_name(quote(foo$bar()))
call_name(quote(foo[[bar]]()))
call_name(quote(foo()()))
# Extract namespace of a call with call_ns():
call_ns(quote(base::bar()))
# If not namespaced, call_ns() returns NULL:
call_ns(quote(bar()))
}
rlang/man/eval_tidy.Rd 0000644 0001762 0000144 00000011505 14175213516 014406 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval-tidy.R
\name{eval_tidy}
\alias{eval_tidy}
\title{Evaluate an expression with quosures and pronoun support}
\usage{
eval_tidy(expr, data = NULL, env = caller_env())
}
\arguments{
\item{expr}{An \link[=topic-defuse]{expression} or
\link[=topic-quosure]{quosure} to evaluate.}
\item{data}{A data frame, or named list or vector. Alternatively, a
data mask created with \code{\link[=as_data_mask]{as_data_mask()}} or
\code{\link[=new_data_mask]{new_data_mask()}}. Objects in \code{data} have priority over those in
\code{env}. See the section about data masking.}
\item{env}{The environment in which to evaluate \code{expr}. This
environment is not applicable for quosures because they have
their own environments.}
}
\description{
\code{eval_tidy()} is a variant of \code{\link[base:eval]{base::eval()}} that powers the tidy
evaluation framework. Like \code{eval()} it accepts user data as
argument. Whereas \code{eval()} simply transforms the data to an
environment, \code{eval_tidy()} transforms it to a \link[=topic-data-mask]{data mask} with \code{\link[=as_data_mask]{as_data_mask()}}. Evaluating in a data
mask enables the following features:
\itemize{
\item \link[=topic-quosure]{Quosures}. Quosures are expressions bundled with
an environment. If \code{data} is supplied, objects in the data mask
always have precedence over the quosure environment, i.e. the
data masks the environment.
\item \link[=.data]{Pronouns}. If \code{data} is supplied, the \code{.env} and \code{.data}
pronouns are installed in the data mask. \code{.env} is a reference to
the calling environment and \code{.data} refers to the \code{data}
argument. These pronouns are an escape hatch for the \link[=topic-data-mask-ambiguity]{data mask ambiguity} problem.
}
}
\section{When should eval_tidy() be used instead of eval()?}{
\code{base::eval()} is sufficient for simple evaluation. Use
\code{eval_tidy()} when you'd like to support expressions referring to
the \code{.data} pronoun, or when you need to support quosures.
If you're evaluating an expression captured with
\link[=topic-inject]{injection} support, it is recommended to use
\code{eval_tidy()} because users may inject quosures.
Note that unwrapping a quosure with \code{\link[=quo_get_expr]{quo_get_expr()}} does not
guarantee that there is no quosures inside the expression. Quosures
might be unquoted anywhere in the expression tree. For instance,
the following does not work reliably in the presence of nested
quosures:\preformatted{my_quoting_fn <- function(x) \{
x <- enquo(x)
expr <- quo_get_expr(x)
env <- quo_get_env(x)
eval(expr, env)
\}
# Works:
my_quoting_fn(toupper(letters))
# Fails because of a nested quosure:
my_quoting_fn(toupper(!!quo(letters)))
}
}
\section{Stack semantics of \code{eval_tidy()}}{
\code{eval_tidy()} always evaluates in a data mask, even when \code{data} is
\code{NULL}. Because of this, it has different stack semantics than
\code{\link[base:eval]{base::eval()}}:
\itemize{
\item Lexical side effects, such as assignment with \verb{<-}, occur in the
mask rather than \code{env}.
\item Functions that require the evaluation environment to correspond
to a frame on the call stack do not work. This is why \code{return()}
called from a quosure does not work.
\item The mask environment creates a new branch in the tree
representation of backtraces (which you can visualise in a
\code{\link[=browser]{browser()}} session with \code{lobstr::cst()}).
}
See also \code{\link[=eval_bare]{eval_bare()}} for more information about these differences.
}
\examples{
# With simple defused expressions eval_tidy() works the same way as
# eval():
fruit <- "apple"
vegetable <- "potato"
expr <- quote(paste(fruit, vegetable, sep = " or "))
expr
eval(expr)
eval_tidy(expr)
# Both accept a data mask as argument:
data <- list(fruit = "banana", vegetable = "carrot")
eval(expr, data)
eval_tidy(expr, data)
# The main difference is that eval_tidy() supports quosures:
with_data <- function(data, expr) {
quo <- enquo(expr)
eval_tidy(quo, data)
}
with_data(NULL, fruit)
with_data(data, fruit)
# eval_tidy() installs the `.data` and `.env` pronouns to allow
# users to be explicit about variable references:
with_data(data, .data$fruit)
with_data(data, .env$fruit)
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-data-mask]{What is data-masking and why do I need \{\{?}}{\link[=topic-data-mask]{What is data-masking and why do I need curly-curly?}}.
\item \ifelse{html}{\link[=topic-quosure]{What are quosures and when are they needed?}}{\link[=topic-quosure]{What are quosures and when are they needed?}}.
\item \ifelse{html}{\link[=topic-defuse]{Defusing R expressions}}{\link[=topic-defuse]{Defusing R expressions}}.
\item \code{\link[=new_data_mask]{new_data_mask()}} and \code{\link[=as_data_mask]{as_data_mask()}} for manually creating data masks.
}
}
rlang/man/rlang_backtrace_on_error.Rd 0000644 0001762 0000144 00000005652 14175213516 017443 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{rlang_backtrace_on_error}
\alias{rlang_backtrace_on_error}
\alias{add_backtrace}
\title{Display backtrace on error}
\description{
rlang errors carry a backtrace that can be inspected by calling
\code{\link[=last_error]{last_error()}}. You can also control the default display of the
backtrace by setting the option \code{rlang_backtrace_on_error} to one
of the following values:
\itemize{
\item \code{"none"} show nothing.
\item \code{"reminder"}, the default in interactive sessions, displays a reminder that
you can see the backtrace with \code{\link[=last_error]{last_error()}}.
\item \code{"branch"} displays a simplified backtrace.
\item \code{"collapse"} displays a collapsed backtrace tree.
\item \code{"full"}, the default in non-interactive sessions, displays the full tree.
}
rlang errors are normally thrown with \code{\link[=abort]{abort()}}. If you promote
base errors to rlang errors with \code{\link[=global_entrace]{global_entrace()}},
\code{rlang_backtrace_on_error} applies to all errors.
}
\section{Promote base errors to rlang errors}{
You can use \code{options(error = rlang::entrace)} to promote base errors to
rlang errors. This does two things:
\itemize{
\item It saves the base error as an rlang object so you can call \code{\link[=last_error]{last_error()}}
to print the backtrace or inspect its data.
\item It prints the backtrace for the current error according to the
\code{rlang_backtrace_on_error} option.
}
}
\section{Errors in RMarkdown}{
The display of errors depends on whether they're expected (i.e.
chunk option \code{error = TRUE}) or unexpected:
\itemize{
\item Expected errors are controlled by the global option
\code{"rlang_backtrace_on_error_report"} (note the \verb{_report} suffix).
The default is \code{"none"} so that your expected errors don't
include a reminder to run \code{rlang::last_error()}. Customise this
option if you want to demonstrate what the error backtrace will
look like.
You can also use \code{\link[=last_error]{last_error()}} to display the trace like you
would in your session, but it currently only works in the next
chunk.
\item Unexpected errors are controlled by the global option
\code{"rlang_backtrace_on_error"}. The default is \code{"branch"} so you'll
see a simplified backtrace in the knitr output to help you figure
out what went wrong.
}
When knitr is running (as determined by the \code{knitr.in.progress}
global option), the default top environment for backtraces is set
to the chunk environment \code{knitr::knit_global()}. This ensures that
the part of the call stack belonging to knitr does not end up in
backtraces. If needed, you can override this by setting the
\code{rlang_trace_top_env} global option.
}
\examples{
# Display a simplified backtrace on error for both base and rlang
# errors:
# options(
# rlang_backtrace_on_error = "branch",
# error = rlang::entrace
# )
# stop("foo")
}
rlang/man/is_symbol.Rd 0000644 0001762 0000144 00000000526 13351410763 014425 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sym.R
\name{is_symbol}
\alias{is_symbol}
\title{Is object a symbol?}
\usage{
is_symbol(x, name = NULL)
}
\arguments{
\item{x}{An object to test.}
\item{name}{An optional name or vector of names that the symbol
should match.}
}
\description{
Is object a symbol?
}
rlang/man/bytes-class.Rd 0000644 0001762 0000144 00000002117 14175213516 014656 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bytes.R
\name{bytes-class}
\alias{bytes-class}
\alias{as_bytes}
\alias{parse_bytes}
\title{Human readable memory sizes}
\usage{
as_bytes(x)
parse_bytes(x)
}
\arguments{
\item{x}{A numeric or character vector. Character representations can use
shorthand sizes (see examples).}
}
\description{
Construct, manipulate and display vectors of byte sizes. These are numeric
vectors, so you can compare them numerically, but they can also be compared
to human readable values such as '10MB'.
\itemize{
\item \code{parse_bytes()} takes a character vector of human-readable bytes
and returns a structured bytes vector.
\item \code{as_bytes()} is a generic conversion function for objects
representing bytes.
}
Note: A \code{bytes()} constructor will be exported soon.
}
\details{
These memory sizes are always assumed to be base 1024, rather than 1000.
}
\examples{
parse_bytes("1")
parse_bytes("1K")
parse_bytes("1Kb")
parse_bytes("1KiB")
parse_bytes("1MB")
parse_bytes("1KB") < "1MB"
sum(parse_bytes(c("1MB", "5MB", "500KB")))
}
rlang/man/op-na-default.Rd 0000644 0001762 0000144 00000001700 14175213516 015056 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/operators.R
\name{op-na-default}
\alias{op-na-default}
\alias{\%|\%}
\title{Replace missing values}
\usage{
x \%|\% y
}
\arguments{
\item{x}{The original values.}
\item{y}{The replacement values. Must be of length 1 or the same length as \code{x}.}
}
\description{
\strong{Note}: This operator is now out of scope for rlang. It will be
replaced by a vctrs-powered operator (probably in the \href{https://github.com/tidyverse/funs}{funs package}) at which point the
rlang version of \verb{\%|\%} will be deprecated.
This infix function is similar to \code{\%||\%} but is vectorised
and provides a default value for missing elements. It is faster
than using \code{\link[base:ifelse]{base::ifelse()}} and does not perform type conversions.
}
\examples{
c("a", "b", NA, "c") \%|\% "default"
c(1L, NA, 3L, NA, NA) \%|\% (6L:10L)
}
\seealso{
\link{op-null-default}
}
\keyword{internal}
rlang/man/is_empty.Rd 0000644 0001762 0000144 00000000524 13351410454 014251 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{is_empty}
\alias{is_empty}
\title{Is object an empty vector or NULL?}
\usage{
is_empty(x)
}
\arguments{
\item{x}{object to test}
}
\description{
Is object an empty vector or NULL?
}
\examples{
is_empty(NULL)
is_empty(list())
is_empty(list(NULL))
}
rlang/man/inject.Rd 0000644 0001762 0000144 00000003114 14175213516 013677 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval.R
\name{inject}
\alias{inject}
\title{Inject objects in an R expression}
\usage{
inject(expr, env = caller_env())
}
\arguments{
\item{expr}{An argument to evaluate. This argument is immediately
evaluated in \code{env} (the current environment by default) with
injected objects and expressions.}
\item{env}{The environment in which to evaluate \code{expr}. Defaults to
the current environment. For expert use only.}
}
\description{
\code{inject()} evaluates an expression with \link[=quasiquotation]{injection}
support. There are three main usages:
\itemize{
\item \link[=!!!]{Splicing} lists of arguments in a function call.
\item Inline objects or other expressions in an expression with \verb{!!}
and \verb{!!!}. For instance to create functions or formulas
programmatically.
\item Pass arguments to NSE functions that \link[=nse-defuse]{defuse} their
arguments without injection support (see for instance
\code{\link[=enquo0]{enquo0()}}). You can use \code{{{ arg }}} with functions documented
to support quosures. Otherwise, use \code{!!enexpr(arg)}.
}
}
\examples{
# inject() simply evaluates its argument with injection
# support. These expressions are equivalent:
2 * 3
inject(2 * 3)
inject(!!2 * !!3)
# Injection with `!!` can be useful to insert objects or
# expressions within other expressions, like formulas:
lhs <- sym("foo")
rhs <- sym("bar")
inject(!!lhs ~ !!rhs + 10)
# Injection with `!!!` splices lists of arguments in function
# calls:
args <- list(na.rm = TRUE, finite = 0.2)
inject(mean(1:10, !!!args))
}
rlang/man/exprs_auto_name.Rd 0000644 0001762 0000144 00000002057 14175213516 015621 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-defuse.R
\name{exprs_auto_name}
\alias{exprs_auto_name}
\alias{quos_auto_name}
\title{Ensure that all elements of a list of expressions are named}
\usage{
exprs_auto_name(
exprs,
...,
repair_auto = c("minimal", "unique"),
repair_quiet = FALSE
)
quos_auto_name(quos)
}
\arguments{
\item{exprs}{A list of expressions.}
\item{...}{These dots are for future extensions and must be empty.}
\item{repair_auto}{Whether to repair the automatic names. By
default, minimal names are returned. See \code{?vctrs::vec_as_names}
for information about name repairing.}
\item{repair_quiet}{Whether to inform user about repaired names.}
\item{quos}{A list of quosures.}
}
\description{
This gives default names to unnamed elements of a list of
expressions (or expression wrappers such as formulas or
quosures). \code{exprs_auto_name()} deparses the expressions with
\code{\link[=expr_name]{expr_name()}} by default. \code{quos_auto_name()} deparses with
\code{\link[=quo_name]{quo_name()}}.
}
rlang/man/local_bindings.Rd 0000644 0001762 0000144 00000003010 14127057575 015375 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{local_bindings}
\alias{local_bindings}
\alias{with_bindings}
\title{Temporarily change bindings of an environment}
\usage{
local_bindings(..., .env = .frame, .frame = caller_env())
with_bindings(.expr, ..., .env = caller_env())
}
\arguments{
\item{...}{Pairs of names and values. These dots support splicing
(with value semantics) and name unquoting.}
\item{.env}{An environment.}
\item{.frame}{The frame environment that determines the scope of
the temporary bindings. When that frame is popped from the call
stack, bindings are switched back to their original values.}
\item{.expr}{An expression to evaluate with temporary bindings.}
}
\value{
\code{local_bindings()} returns the values of old bindings
invisibly; \code{with_bindings()} returns the value of \code{expr}.
}
\description{
\itemize{
\item \code{local_bindings()} temporarily changes bindings in \code{.env} (which
is by default the caller environment). The bindings are reset to
their original values when the current frame (or an arbitrary one
if you specify \code{.frame}) goes out of scope.
\item \code{with_bindings()} evaluates \code{expr} with temporary bindings. When
\code{with_bindings()} returns, bindings are reset to their original
values. It is a simple wrapper around \code{local_bindings()}.
}
}
\examples{
foo <- "foo"
bar <- "bar"
# `foo` will be temporarily rebinded while executing `expr`
with_bindings(paste(foo, bar), foo = "rebinded")
paste(foo, bar)
}
rlang/man/cnd.Rd 0000644 0001762 0000144 00000004552 14176512327 013201 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd.R
\name{cnd}
\alias{cnd}
\alias{error_cnd}
\alias{warning_cnd}
\alias{message_cnd}
\title{Create a condition object}
\usage{
cnd(class, ..., message = "", call = NULL, use_cli_format = NULL)
error_cnd(
class = NULL,
...,
message = "",
call = NULL,
trace = NULL,
parent = NULL,
use_cli_format = NULL
)
warning_cnd(
class = NULL,
...,
message = "",
call = NULL,
use_cli_format = NULL
)
message_cnd(
class = NULL,
...,
message = "",
call = NULL,
use_cli_format = NULL
)
}
\arguments{
\item{class}{The condition subclass.}
\item{...}{<\link[=dyn-dots]{dynamic}> Named data fields stored inside
the condition object.}
\item{message}{A default message to inform the user about the
condition when it is signalled.}
\item{call}{A function call to be included in the error message.
If an execution environment of a running function, the
corresponding function call is retrieved.}
\item{use_cli_format}{Whether to use the cli package to format
\code{message}. See \code{\link[=local_use_cli]{local_use_cli()}}.}
\item{trace}{A \code{trace} object created by \code{\link[=trace_back]{trace_back()}}.}
\item{parent}{A parent condition object.}
}
\description{
These constructors create subclassed conditions, the objects that
power the error, warning, and message system in R.
\itemize{
\item \code{cnd()} creates bare conditions that only inherit from
\code{condition}.
\item Conditions created with \code{error_cnd()}, \code{warning_cnd()}, and
\code{message_cnd()} inherit from \code{"error"}, \code{"warning"}, or \code{"message"}.
\item \code{error_cnd()} creates subclassed errors. See
\code{\link[=rlang_error]{"rlang_error"}}.
}
Use \code{\link[=cnd_signal]{cnd_signal()}} to emit the relevant signal for a particular
condition class.
}
\examples{
# Create a condition inheriting only from the S3 class "foo":
cnd <- cnd("foo")
# Signal the condition to potential handlers. Since this is a bare
# condition the signal has no effect if no handlers are set up:
cnd_signal(cnd)
# When a relevant handler is set up, the signal transfers control
# to the handler
with_handlers(cnd_signal(cnd), foo = function(c) "caught!")
tryCatch(cnd_signal(cnd), foo = function(c) "caught!")
}
\seealso{
\code{\link[=cnd_signal]{cnd_signal()}}, \code{\link[=try_fetch]{try_fetch()}}.
}
\keyword{internal}
rlang/man/qq_show.Rd 0000644 0001762 0000144 00000002347 14175213516 014113 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-inject.R
\name{qq_show}
\alias{qq_show}
\title{Show injected expression}
\arguments{
\item{expr}{An expression involving \link[=topic-inject]{injection operators}.}
}
\description{
\code{qq_show()} helps examining \link[=topic-inject]{injected expressions}
inside a function. This is useful for learning about injection and
for debugging injection code.
}
\section{Examples}{
\code{qq_show()} shows the intermediary expression before it is
evaluated by R:\if{html}{\out{
}}
It is especially useful inside functions to reveal what an injected
expression looks like:\if{html}{\out{
}}\preformatted{my_mean <- function(data, var) \{
qq_show(data \%>\% dplyr::summarise(mean(\{\{ var \}\})))
\}
mtcars \%>\% my_mean(cyl)
#> data \%>\% dplyr::summarise(mean(^cyl))
}\if{html}{\out{
}}
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}
}
}
rlang/man/as_closure.Rd 0000644 0001762 0000144 00000003035 14175213516 014564 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{as_closure}
\alias{as_closure}
\title{Transform to a closure}
\usage{
as_closure(x, env = caller_env())
}
\arguments{
\item{x}{A function or formula.
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function
with up to two arguments: \code{.x} (single argument) or \code{.x} and \code{.y}
(two arguments). The \code{.} placeholder can be used instead of \code{.x}.
This allows you to create very compact anonymous functions (lambdas) with up
to two inputs. Functions created from formulas have a special
class. Use \code{is_lambda()} to test for it.
If a \strong{string}, the function is looked up in \code{env}. Note that
this interface is strictly for user convenience because of the
scoping issues involved. Package developers should avoid
supplying functions by name and instead supply them by value.}
\item{env}{Environment in which to fetch the function in case \code{x}
is a string.}
}
\description{
\code{as_closure()} is like \code{\link[=as_function]{as_function()}} but also wraps primitive
functions inside closures. Some special control flow primitives
like \code{if}, \code{for}, or \code{break} can't be wrapped and will cause an
error.
}
\examples{
# Primitive functions are regularised as closures
as_closure(list)
as_closure("list")
# Operators have `.x` and `.y` as arguments, just like lambda
# functions created with the formula syntax:
as_closure(`+`)
as_closure(`~`)
}
\keyword{internal}
rlang/man/expr.Rd 0000644 0001762 0000144 00000003026 14175213516 013403 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-defuse.R
\name{expr}
\alias{expr}
\title{Defuse an R expression}
\arguments{
\item{expr}{An expression to defuse.}
}
\description{
\code{expr()} \link[=topic-defuse]{defuses} an R expression with
\link[=injection-operator]{injection} support.
It is equivalent to \code{\link[base:bquote]{base::bquote()}}.
}
\examples{
# R normally returns the result of an expression
1 + 1
# `expr()` defuses the expression that you have supplied and
# returns it instead of its value
expr(1 + 1)
expr(toupper(letters))
# It supports _injection_ with `!!` and `!!!`. This is a convenient
# way of modifying part of an expression by injecting other
# objects.
var <- "cyl"
expr(with(mtcars, mean(!!sym(var))))
vars <- c("cyl", "am")
expr(with(mtcars, c(!!!syms(vars))))
# Compare to the normal way of building expressions
call("with", call("mean", sym(var)))
call("with", call2("c", !!!syms(vars)))
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-defuse]{Defusing R expressions}}{\link[=topic-defuse]{Defusing R expressions}} for an overview.
\item \code{\link[=enquo]{enquo()}} to defuse non-local expressions from function
arguments.
\item \link[=defusing-advanced]{Advanced defusal operators}.
\item \code{\link[=sym]{sym()}} and \code{\link[=call2]{call2()}} for building expressions (symbols and calls
respectively) programmatically.
\item \code{\link[base:eval]{base::eval()}} and \code{\link[=eval_bare]{eval_bare()}} for resuming evaluation
of a defused expression.
}
}
rlang/man/lang.Rd 0000644 0001762 0000144 00000001452 14175213516 013347 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{lang}
\alias{lang}
\title{Create a call}
\usage{
lang(.fn, ..., .ns = NULL)
}
\arguments{
\item{.fn}{Function to call. Must be a callable object: a string,
symbol, call, or a function.}
\item{...}{<\link[=dyn-dots]{dynamic}> Arguments for the function
call. Empty arguments are preserved.}
\item{.ns}{Namespace with which to prefix \code{.fn}. Must be a string
or symbol.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
These functions are deprecated, please use \code{\link[=call2]{call2()}} and
\code{\link[=new_call]{new_call()}} instead.
}
\keyword{internal}
rlang/man/is_callable.Rd 0000644 0001762 0000144 00000002263 14137447476 014675 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{is_callable}
\alias{is_callable}
\title{Is an object callable?}
\usage{
is_callable(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
A callable object is an object that can appear in the function
position of a call (as opposed to argument position). This includes
\link[=is_symbolic]{symbolic objects} that evaluate to a function or
literal functions embedded in the call.
}
\details{
Note that strings may look like callable objects because
expressions of the form \code{"list"()} are valid R code. However,
that's only because the R parser transforms strings to symbols. It
is not legal to manually set language heads to strings.
}
\examples{
# Symbolic objects and functions are callable:
is_callable(quote(foo))
is_callable(base::identity)
# node_poke_car() lets you modify calls without any checking:
lang <- quote(foo(10))
node_poke_car(lang, current_env())
# Use is_callable() to check an input object is safe to put as CAR:
obj <- base::identity
if (is_callable(obj)) {
lang <- node_poke_car(lang, obj)
} else {
abort("`obj` must be callable")
}
eval_bare(lang)
}
\keyword{internal}
rlang/man/obj_address.Rd 0000644 0001762 0000144 00000000500 14175213516 014676 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/obj.R
\name{obj_address}
\alias{obj_address}
\title{Address of an R object}
\usage{
obj_address(x)
}
\arguments{
\item{x}{Any R object.}
}
\value{
Its address in memory in a string.
}
\description{
Address of an R object
}
\keyword{internal}
rlang/man/are_na.Rd 0000644 0001762 0000144 00000003327 14175213516 013656 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vec-na.R
\name{are_na}
\alias{are_na}
\alias{is_na}
\alias{is_lgl_na}
\alias{is_int_na}
\alias{is_dbl_na}
\alias{is_chr_na}
\alias{is_cpl_na}
\title{Test for missing values}
\usage{
are_na(x)
is_na(x)
is_lgl_na(x)
is_int_na(x)
is_dbl_na(x)
is_chr_na(x)
is_cpl_na(x)
}
\arguments{
\item{x}{An object to test}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#questioning}{\figure{lifecycle-questioning.svg}{options: alt='[Questioning]'}}}{\strong{[Questioning]}}
\code{are_na()} checks for missing values in a vector and is equivalent
to \code{\link[base:NA]{base::is.na()}}. It is a vectorised predicate, meaning that its
output is always the same length as its input. On the other hand,
\code{is_na()} is a scalar predicate and always returns a scalar
boolean, \code{TRUE} or \code{FALSE}. If its input is not scalar, it returns
\code{FALSE}. Finally, there are typed versions that check for
particular \link[=missing]{missing types}.
}
\details{
The scalar predicates accept non-vector inputs. They are equivalent
to \code{\link[=is_null]{is_null()}} in that respect. In contrast the vectorised
predicate \code{are_na()} requires a vector input since it is defined
over vector values.
}
\section{Life cycle}{
These functions might be moved to the vctrs package at some
point. This is why they are marked as questioning.
}
\examples{
# are_na() is vectorised and works regardless of the type
are_na(c(1, 2, NA))
are_na(c(1L, NA, 3L))
# is_na() checks for scalar input and works for all types
is_na(NA)
is_na(na_dbl)
is_na(character(0))
# There are typed versions as well:
is_lgl_na(NA)
is_lgl_na(na_dbl)
}
\keyword{internal}
rlang/man/englue.Rd 0000644 0001762 0000144 00000003226 14175213516 013706 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-inject.R
\name{englue}
\alias{englue}
\title{Defuse function arguments with glue}
\usage{
englue(x)
}
\arguments{
\item{x}{A string to interpolate with glue operators.}
}
\description{
\code{englue()} creates a string with the \link[=glue-operators]{glue operators} \verb{\{} and \verb{\{\{}. These operators are
normally used to inject names within \link[=dyn-dots]{dynamic dots}.
\code{englue()} makes them available anywhere within a function.
\code{englue()} must be used inside a function. \code{englue("{{ var }}")}
\link[=topic-defuse]{defuses} the argument \code{var} and transforms it to a
string using the default name operation.
}
\details{
\code{englue("{{ var }}")} is equivalent to \code{as_label(enquo(var))}. It
\link[=topic-defuse]{defuses} \code{arg} and transforms the expression to a
string with \code{\link[=as_label]{as_label()}}.
In dynamic dots, using only \verb{\{} is allowed. In \code{englue()} you must
use \verb{\{\{} at least once. Use \code{glue::glue()} for simple
interpolation.
Before using \code{englue()} in a package, first ensure that glue is
installed by adding it to your \verb{Imports:} section.\if{html}{\out{
}}
}
\examples{
g <- function(var) englue("{{ var }}")
g(cyl)
g(1 + 1)
g(!!letters)
# These are equivalent to
as_label(quote(cyl))
as_label(quote(1 + 1))
as_label(letters)
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}{\link[=topic-inject]{Injecting with !!, !!!, and glue syntax}}
}
}
rlang/man/op-get-attr.Rd 0000644 0001762 0000144 00000001472 14127057575 014603 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/operators.R
\name{op-get-attr}
\alias{op-get-attr}
\alias{\%@\%}
\alias{\%@\%<-}
\title{Infix attribute accessor and setter}
\usage{
x \%@\% name
x \%@\% name <- value
}
\arguments{
\item{x}{Object}
\item{name}{Attribute name}
\item{value}{New value for attribute \code{name}.}
}
\description{
This operator extracts or sets attributes for regular objects and
S4 fields for S4 objects.
}
\examples{
# Unlike `@`, this operator extracts attributes for any kind of
# objects:
factor(1:3) \%@\% "levels"
mtcars \%@\% class
mtcars \%@\% class <- NULL
mtcars
# It also works on S4 objects:
.Person <- setClass("Person", slots = c(name = "character", species = "character"))
fievel <- .Person(name = "Fievel", species = "mouse")
fievel \%@\% name
}
rlang/man/cnd_type.Rd 0000644 0001762 0000144 00000001005 14127057575 014235 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd.R
\name{cnd_type}
\alias{cnd_type}
\title{What type is a condition?}
\usage{
cnd_type(cnd)
}
\arguments{
\item{cnd}{A condition object.}
}
\value{
A string, either \code{"condition"}, \code{"message"}, \code{"warning"},
\code{"error"} or \code{"interrupt"}.
}
\description{
Use \code{cnd_type()} to check what type a condition is.
}
\examples{
cnd_type(catch_cnd(abort("Abort!")))
cnd_type(catch_cnd(interrupt()))
}
\keyword{internal}
rlang/man/new_formula.Rd 0000644 0001762 0000144 00000000744 13351410454 014742 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/formula.R
\name{new_formula}
\alias{new_formula}
\title{Create a formula}
\usage{
new_formula(lhs, rhs, env = caller_env())
}
\arguments{
\item{lhs, rhs}{A call, name, or atomic vector.}
\item{env}{An environment.}
}
\value{
A formula object.
}
\description{
Create a formula
}
\examples{
new_formula(quote(a), quote(b))
new_formula(NULL, quote(b))
}
\seealso{
\code{\link[=new_quosure]{new_quosure()}}
}
rlang/man/empty_env.Rd 0000644 0001762 0000144 00000000732 14127057575 014444 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-special.R
\name{empty_env}
\alias{empty_env}
\title{Get the empty environment}
\usage{
empty_env()
}
\description{
The empty environment is the only one that does not have a parent.
It is always used as the tail of an environment chain such as the
search path (see \code{\link[=search_envs]{search_envs()}}).
}
\examples{
# Create environments with nothing in scope:
child_env(empty_env())
}
rlang/man/check_required.Rd 0000644 0001762 0000144 00000001643 14175213516 015405 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg.R
\name{check_required}
\alias{check_required}
\title{Check that argument is supplied}
\usage{
check_required(x, arg = caller_arg(x), call = caller_env())
}
\arguments{
\item{x}{A function argument. Must be a symbol.}
\item{arg}{An argument name as a string. This argument
will be mentioned in error messages as the input that is at the
origin of a problem.}
\item{call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\description{
Throws an error if \code{x} is missing.
}
\examples{
f <- function(x) {
check_required(x)
}
# Fails because `x` is not supplied
try(f())
# Succeeds
f(NULL)
}
\seealso{
\code{\link[=arg_match]{arg_match()}}
}
rlang/man/is_weakref.Rd 0000644 0001762 0000144 00000000420 14127057575 014547 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weakref.R
\name{is_weakref}
\alias{is_weakref}
\title{Is object a weak reference?}
\usage{
is_weakref(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
Is object a weak reference?
}
rlang/man/call_fn.Rd 0000644 0001762 0000144 00000001206 14175213516 014021 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{call_fn}
\alias{call_fn}
\title{Extract function from a call}
\usage{
call_fn(call, env = caller_env())
}
\arguments{
\item{call, env}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Deprecated in rlang 0.4.11.
}
\keyword{internal}
rlang/man/invoke.Rd 0000644 0001762 0000144 00000001366 14175213516 013725 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{invoke}
\alias{invoke}
\title{Invoke a function with a list of arguments}
\usage{
invoke(.fn, .args = list(), ..., .env = caller_env(), .bury = c(".fn", ""))
}
\arguments{
\item{.fn, args, ..., .env, .bury}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
Deprecated in rlang 0.4.0 in favour of \code{\link[=exec]{exec()}}.
}
\keyword{internal}
rlang/man/as_environment.Rd 0000644 0001762 0000144 00000002464 14175213516 015461 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{as_environment}
\alias{as_environment}
\title{Coerce to an environment}
\usage{
as_environment(x, parent = NULL)
}
\arguments{
\item{x}{An object to coerce.}
\item{parent}{A parent environment, \code{\link[=empty_env]{empty_env()}} by default. This
argument is only used when \code{x} is data actually coerced to an
environment (as opposed to data representing an environment, like
\code{NULL} representing the empty environment).}
}
\description{
\code{as_environment()} coerces named vectors (including lists) to an
environment. The names must be unique. If supplied an unnamed
string, it returns the corresponding package environment (see
\code{\link[=pkg_env]{pkg_env()}}).
}
\details{
If \code{x} is an environment and \code{parent} is not \code{NULL}, the
environment is duplicated before being set a new parent. The return
value is therefore a different environment than \code{x}.
}
\examples{
# Coerce a named vector to an environment:
env <- as_environment(mtcars)
# By default it gets the empty environment as parent:
identical(env_parent(env), empty_env())
# With strings it is a handy shortcut for pkg_env():
as_environment("base")
as_environment("rlang")
# With NULL it returns the empty environment:
as_environment(NULL)
}
rlang/man/is_true.Rd 0000644 0001762 0000144 00000000710 14137447476 014110 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{is_true}
\alias{is_true}
\alias{is_false}
\title{Is object identical to TRUE or FALSE?}
\usage{
is_true(x)
is_false(x)
}
\arguments{
\item{x}{object to test}
}
\description{
These functions bypass R's automatic conversion rules and check
that \code{x} is literally \code{TRUE} or \code{FALSE}.
}
\examples{
is_true(TRUE)
is_true(1)
is_false(FALSE)
is_false(0)
}
rlang/man/expr_print.Rd 0000644 0001762 0000144 00000004140 14175213516 014615 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expr.R
\name{expr_print}
\alias{expr_print}
\alias{expr_deparse}
\title{Print an expression}
\usage{
expr_print(x, ...)
expr_deparse(x, ..., width = peek_option("width"))
}
\arguments{
\item{x}{An object or expression to print.}
\item{...}{Arguments passed to \code{expr_deparse()}.}
\item{width}{The width of the deparsed or printed expression.
Defaults to the global option \code{width}.}
}
\value{
\code{expr_deparse()} returns a character vector of lines.
\code{expr_print()} returns its input invisibly.
}
\description{
\code{expr_print()}, powered by \code{expr_deparse()}, is an alternative
printer for R expressions with a few improvements over the base R
printer.
\itemize{
\item It colourises \link[=nse-defuse]{quosures} according to their environment.
Quosures from the global environment are printed normally while
quosures from local environments are printed in unique colour (or
in italic when all colours are taken).
\item It wraps inlined objects in angular brackets. For instance, an
integer vector unquoted in a function call (e.g.
\code{expr(foo(!!(1:3)))}) is printed like this: \verb{foo()} while by default R prints the code to create that vector:
\code{foo(1:3)} which is ambiguous.
\item It respects the width boundary (from the global option \code{width})
in more cases.
}
}
\examples{
# It supports any object. Non-symbolic objects are always printed
# within angular brackets:
expr_print(1:3)
expr_print(function() NULL)
# Contrast this to how the code to create these objects is printed:
expr_print(quote(1:3))
expr_print(quote(function() NULL))
# The main cause of non-symbolic objects in expressions is
# quasiquotation:
expr_print(expr(foo(!!(1:3))))
# Quosures from the global environment are printed normally:
expr_print(quo(foo))
expr_print(quo(foo(!!quo(bar))))
# Quosures from local environments are colourised according to
# their environments (if you have crayon installed):
local_quo <- local(quo(foo))
expr_print(local_quo)
wrapper_quo <- local(quo(bar(!!local_quo, baz)))
expr_print(wrapper_quo)
}
rlang/man/expr_interp.Rd 0000644 0001762 0000144 00000001326 14175213516 014765 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{expr_interp}
\alias{expr_interp}
\title{Process unquote operators in a captured expression}
\usage{
expr_interp(x, env = NULL)
}
\arguments{
\item{x, env}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
\code{expr_interp()} is deprecated, please use \code{\link[=inject]{inject()}} instead.
}
\keyword{internal}
rlang/man/env_get.Rd 0000644 0001762 0000144 00000003074 14175213516 014057 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_get}
\alias{env_get}
\alias{env_get_list}
\title{Get an object in an environment}
\usage{
env_get(env = caller_env(), nm, default, inherit = FALSE, last = empty_env())
env_get_list(
env = caller_env(),
nms,
default,
inherit = FALSE,
last = empty_env()
)
}
\arguments{
\item{env}{An environment.}
\item{nm, nms}{Names of bindings. \code{nm} must be a single string.}
\item{default}{A default value in case there is no binding for \code{nm}
in \code{env}.}
\item{inherit}{Whether to look for bindings in the parent
environments.}
\item{last}{Last environment inspected when \code{inherit} is \code{TRUE}.
Can be useful in conjunction with \code{\link[base:ns-topenv]{base::topenv()}}.}
}
\value{
An object if it exists. Otherwise, throws an error.
}
\description{
\code{env_get()} extracts an object from an enviroment \code{env}. By
default, it does not look in the parent environments.
\code{env_get_list()} extracts multiple objects from an environment into
a named list.
}
\examples{
parent <- child_env(NULL, foo = "foo")
env <- child_env(parent, bar = "bar")
# This throws an error because `foo` is not directly defined in env:
# env_get(env, "foo")
# However `foo` can be fetched in the parent environment:
env_get(env, "foo", inherit = TRUE)
# You can also avoid an error by supplying a default value:
env_get(env, "foo", default = "FOO")
}
\seealso{
\code{\link[=env_cache]{env_cache()}} for a variant of \code{env_get()} designed to
cache a value in an environment.
}
rlang/man/last_error.Rd 0000644 0001762 0000144 00000001615 14175213516 014603 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-last.R
\name{last_error}
\alias{last_error}
\alias{last_trace}
\title{Last \code{abort()} error}
\usage{
last_error()
last_trace()
}
\description{
\itemize{
\item \code{last_error()} returns the last error entraced by \code{\link[=abort]{abort()}} or
\code{\link[=global_entrace]{global_entrace()}}. The error is printed with a backtrace in
simplified form.
\item \code{last_trace()} is a shortcut to return the backtrace stored in
the last error. This backtrace is printed in full form.
}
}
\seealso{
\itemize{
\item \code{\link{rlang_backtrace_on_error}} to control what is displayed when an
error is thrown.
\item \code{\link[=global_entrace]{global_entrace()}} to enable \code{last_error()} logging for all errors.
\item \code{\link[=last_warnings]{last_warnings()}} and \code{\link[=last_messages]{last_messages()}}.
}
}
rlang/man/new_call.Rd 0000644 0001762 0000144 00000000746 14175213516 014217 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/node.R
\name{new_call}
\alias{new_call}
\title{Create a new call from components}
\usage{
new_call(car, cdr = NULL)
}
\arguments{
\item{car}{The head of the call. It should be a
\link[=is_callable]{callable} object: a symbol, call, or literal
function.}
\item{cdr}{The tail of the call, i.e. a \link[=new_node]{pairlist} of
arguments.}
}
\description{
Create a new call from components
}
\keyword{internal}
rlang/man/splice.Rd 0000644 0001762 0000144 00000010535 14175213516 013707 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots.R
\name{splice}
\alias{splice}
\alias{is_spliced}
\alias{is_spliced_bare}
\alias{dots_splice}
\title{Splice lists}
\usage{
splice(x)
is_spliced(x)
is_spliced_bare(x)
dots_splice(
...,
.ignore_empty = c("trailing", "none", "all"),
.preserve_empty = FALSE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
}
\arguments{
\item{x}{A list to splice.}
\item{...}{Arguments to collect in a list. These dots are
\link[=dyn-dots]{dynamic}.}
\item{.ignore_empty}{Whether to ignore empty arguments. Can be one
of \code{"trailing"}, \code{"none"}, \code{"all"}. If \code{"trailing"}, only the
last argument is ignored if it is empty.}
\item{.preserve_empty}{Whether to preserve the empty arguments that
were not ignored. If \code{TRUE}, empty arguments are stored with
\code{\link[=missing_arg]{missing_arg()}} values. If \code{FALSE} (the default) an error is
thrown when an empty argument is detected.}
\item{.homonyms}{How to treat arguments with the same name. The
default, \code{"keep"}, preserves these arguments. Set \code{.homonyms} to
\code{"first"} to only keep the first occurrences, to \code{"last"} to keep
the last occurrences, and to \code{"error"} to raise an informative
error and indicate what arguments have duplicated names.}
\item{.check_assign}{Whether to check for \verb{<-} calls. When \code{TRUE} a
warning recommends users to use \code{=} if they meant to match a
function parameter or wrap the \verb{<-} call in curly braces otherwise.
This ensures assignments are explicit.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#questioning}{\figure{lifecycle-questioning.svg}{options: alt='[Questioning]'}}}{\strong{[Questioning]}}
\itemize{
\item \code{splice} marks an object to be spliced. It is equivalent to using
\verb{!!!} in a function taking \link[=dyn-dots]{dynamic dots}.
\item \code{dots_splice()} is like \code{\link[=dots_list]{dots_list()}} but automatically splices
list inputs.
}
}
\section{Standard splicing versus quoting splicing}{
The \verb{!!!} operator works differently in \emph{standard} functions taking
dots with \code{dots_list()} than in \emph{quoting} functions taking dots
with \code{\link[=enexprs]{enexprs()}} or \code{\link[=enquos]{enquos()}}.
\itemize{
\item In quoting functions \verb{!!!} disaggregates its argument (let's call
it \code{x}) into as many objects as there are elements in
\code{x}. E.g. \code{quo(foo(!!! c(1, 2)))} is completely equivalent to
\code{quo(foo(1, 2))}. The creation of those separate objects has an
overhead but is typically not important when manipulating calls
because function calls typically take a small number of
arguments.
\item In standard functions, disaggregating the spliced collection
would have a negative performance impact in cases where
\code{dots_list()} is used to build up data structures from user
inputs. To avoid this spliced inputs are marked with \code{\link[=splice]{splice()}}
and the final list is built with (the equivalent of)
\code{flatten_if(dots, is_spliced)}.
}
Most of the time you should not care about the difference. However
if you use a standard function taking tidy dots within a quoting
function, the \verb{!!!} operator will disaggregate its argument because
the behaviour of the quasiquoting function has priority. You might
then observe some performance cost in edge cases. Here is one
example where this would happen:\preformatted{purrr::rerun(10, dplyr::bind_rows(!!! x))
}
\code{purrr::rerun()} is a quoting function and \code{dplyr::bind_rows()} is
a standard function. Because \code{bind_rows()} is called \emph{inside}
\code{rerun()}, the list \code{x} will be disaggregated into a pairlist of
arguments. To avoid this you can use \code{splice()} instead:\preformatted{purrr::rerun(10, dplyr::bind_rows(splice(x)))
}
}
\section{Life cycle}{
\itemize{
\item \code{dots_splice()} is in the questioning stage. It is part of our
experiments with dots semantics. Compared to \code{dots_list()},
\code{dots_splice()} automatically splices lists. We now lean towards
adopting a single type of dots semantics (those of \code{dots_list()})
where splicing is explicit.
\item \code{splice()} is in the questioning stage. It is not clear whether it is
really needed as there are other ways to avoid the performance
issue discussed above.
}
}
\keyword{internal}
rlang/man/new_weakref.Rd 0000644 0001762 0000144 00000005054 14127057575 014735 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weakref.R
\name{new_weakref}
\alias{new_weakref}
\title{Create a weak reference}
\usage{
new_weakref(key, value = NULL, finalizer = NULL, on_quit = FALSE)
}
\arguments{
\item{key}{The key for the weak reference. Must be a reference object -- that
is, an environment or external pointer.}
\item{value}{The value for the weak reference. This can be \code{NULL}, if you
want to use the weak reference like a weak pointer.}
\item{finalizer}{A function that is run after the key becomes unreachable.}
\item{on_quit}{Should the finalizer be run when R exits?}
}
\description{
A weak reference is a special R object which makes it possible to keep a
reference to an object without preventing garbage collection of that object.
It can also be used to keep data about an object without preventing GC of the
object, similar to WeakMaps in JavaScript.
Objects in R are considered \emph{reachable} if they can be accessed by following
a chain of references, starting from a \emph{root node}; root nodes are
specially-designated R objects, and include the global environment and base
environment. As long as the key is reachable, the value will not be garbage
collected. This is true even if the weak reference object becomes
unreachable. The key effectively prevents the weak reference and its value
from being collected, according to the following chain of ownership:
\code{weakref <- key -> value}.
When the key becomes unreachable, the key and value in the weak reference
object are replaced by \code{NULL}, and the finalizer is scheduled to execute.
}
\examples{
e <- env()
# Create a weak reference to e
w <- new_weakref(e, finalizer = function(e) message("finalized"))
# Get the key object from the weak reference
identical(wref_key(w), e)
# When the regular reference (the `e` binding) is removed and a GC occurs,
# the weak reference will not keep the object alive.
rm(e)
gc()
identical(wref_key(w), NULL)
# A weak reference with a key and value. The value contains data about the
# key.
k <- env()
v <- list(1, 2, 3)
w <- new_weakref(k, v)
identical(wref_key(w), k)
identical(wref_value(w), v)
# When v is removed, the weak ref keeps it alive because k is still reachable.
rm(v)
gc()
identical(wref_value(w), list(1, 2, 3))
# When k is removed, the weak ref does not keep k or v alive.
rm(k)
gc()
identical(wref_key(w), NULL)
identical(wref_value(w), NULL)
}
\seealso{
\code{\link[=is_weakref]{is_weakref()}}, \code{\link[=wref_key]{wref_key()}} and \code{\link[=wref_value]{wref_value()}}.
}
\keyword{experimental}
rlang/man/faq-options.Rd 0000644 0001762 0000144 00000002135 14127057575 014675 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/faq.R
\name{faq-options}
\alias{faq-options}
\title{Global options for rlang}
\description{
rlang has several options which may be set globally to control
behavior. A brief description of each is given here. If any functions
are referenced, refer to their documentation for additional details.
\itemize{
\item \code{rlang_interactive}: A logical value used by \code{\link[=is_interactive]{is_interactive()}}. This
can be set to \code{TRUE} to test interactive behavior in unit tests,
for example.
\item \code{rlang_backtrace_on_error}: A character string which controls whether
backtraces are displayed with error messages, and the level of
detail they print. See \link{rlang_backtrace_on_error} for the possible option values.
\item \code{rlang_trace_format_srcrefs}: A logical value used to control whether
srcrefs are printed as part of the backtrace.
\item \code{rlang_trace_top_env}: An environment which will be treated as the
top-level environment when printing traces. See \code{\link[=trace_back]{trace_back()}}
for examples.
}
}
rlang/man/catch_cnd.Rd 0000644 0001762 0000144 00000001477 14127057575 014353 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-handlers.R
\name{catch_cnd}
\alias{catch_cnd}
\title{Catch a condition}
\usage{
catch_cnd(expr, classes = "condition")
}
\arguments{
\item{expr}{Expression to be evaluated with a catching condition
handler.}
\item{classes}{A character vector of condition classes to catch. By
default, catches all conditions.}
}
\value{
A condition if any was signalled, \code{NULL} otherwise.
}
\description{
This is a small wrapper around \code{tryCatch()} that captures any
condition signalled while evaluating its argument. It is useful for
situations where you expect a specific condition to be signalled,
for debugging, and for unit testing.
}
\examples{
catch_cnd(10)
catch_cnd(abort("an error"))
catch_cnd(signal("my_condition", message = "a condition"))
}
rlang/man/vector-coercion.Rd 0000644 0001762 0000144 00000010360 14175213516 015525 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{vector-coercion}
\alias{vector-coercion}
\alias{as_logical}
\alias{as_integer}
\alias{as_double}
\alias{as_complex}
\alias{as_character}
\alias{as_list}
\title{Coerce an object to a base type}
\usage{
as_logical(x)
as_integer(x)
as_double(x)
as_complex(x)
as_character(x, encoding = NULL)
as_list(x)
}
\arguments{
\item{x}{An object to coerce to a base type.}
\item{encoding}{If non-null, set an encoding mark. This is only
declarative, no encoding conversion is performed.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#soft-deprecated}{\figure{lifecycle-soft-deprecated.svg}{options: alt='[Soft-deprecated]'}}}{\strong{[Soft-deprecated]}}
These are equivalent to the base functions (e.g. \code{\link[=as.logical]{as.logical()}},
\code{\link[=as.list]{as.list()}}, etc), but perform coercion rather than conversion.
This means they are not generic and will not call S3 conversion
methods. They only attempt to coerce the base type of their
input. In addition, they have stricter implicit coercion rules and
will never attempt any kind of parsing. E.g. they will not try to
figure out if a character vector represents integers or booleans.
Finally, they treat attributes consistently, unlike the base R
functions: all attributes except names are removed.
}
\section{Lifecycle}{
These functions are deprecated in favour of \code{vctrs::vec_cast()}.
}
\section{Coercion to logical and numeric atomic vectors}{
\itemize{
\item To logical vectors: Integer and integerish double vectors. See
\code{\link[=is_integerish]{is_integerish()}}.
\item To integer vectors: Logical and integerish double vectors.
\item To double vectors: Logical and integer vectors.
\item To complex vectors: Logical, integer and double vectors.
}
}
\section{Coercion to character vectors}{
\code{as_character()} and \code{as_string()} have an optional \code{encoding}
argument to specify the encoding. R uses this information for
internal handling of strings and character vectors. Note that this
is only declarative, no encoding conversion is attempted.
Note that only \code{as_string()} can coerce symbols to a scalar
character vector. This makes the code more explicit and adds an
extra type check.
}
\section{Coercion to lists}{
\code{as_list()} only coerces vector and dictionary types (environments
are an example of dictionary type). Unlike \code{\link[base:list]{base::as.list()}},
\code{as_list()} removes all attributes except names.
}
\section{Effects of removing attributes}{
A technical side-effect of removing the attributes of the input is
that the underlying objects has to be copied. This has no
performance implications in the case of lists because this is a
shallow copy: only the list structure is copied, not the contents
(see \code{\link[=duplicate]{duplicate()}}). However, be aware that atomic vectors
containing large amounts of data will have to be copied.
In general, any attribute modification creates a copy, which is why
it is better to avoid using attributes with heavy atomic vectors.
Uncopyable objects like environments and symbols are an exception
to this rule: in this case, attributes modification happens in
place and has side-effects.
}
\examples{
# Coercing atomic vectors removes attributes with both base R and rlang:
x <- structure(TRUE, class = "foo", bar = "baz")
as.logical(x)
# But coercing lists preserves attributes in base R but not rlang:
l <- structure(list(TRUE), class = "foo", bar = "baz")
as.list(l)
as_list(l)
# Implicit conversions are performed in base R but not rlang:
as.logical(l)
\dontrun{
as_logical(l)
}
# Conversion methods are bypassed, making the result of the
# coercion more predictable:
as.list.foo <- function(x) "wrong"
as.list(l)
as_list(l)
# The input is never parsed. E.g. character vectors of numbers are
# not converted to numeric types:
as.integer("33")
\dontrun{
as_integer("33")
}
# With base R tools there is no way to convert an environment to a
# list without either triggering method dispatch, or changing the
# original environment. as_list() makes it easy:
x <- structure(as_environment(mtcars[1:2]), class = "foobar")
as.list.foobar <- function(x) abort("dont call me")
as_list(x)
}
\keyword{internal}
rlang/man/env_print.Rd 0000644 0001762 0000144 00000002131 14127057575 014435 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{env_print}
\alias{env_print}
\title{Pretty-print an environment}
\usage{
env_print(env = caller_env())
}
\arguments{
\item{env}{An environment, or object that can be converted to an
environment by \code{\link[=get_env]{get_env()}}.}
}
\description{
This prints:
\itemize{
\item The \link[=env_label]{label} and the parent label.
\item Whether the environment is \link[=env_lock]{locked}.
\item The bindings in the environment (up to 20 bindings). They are
printed succintly using \code{pillar::type_sum()} (if available,
otherwise uses an internal version of that generic). In addition
\link[=env_bind_lazy]{fancy bindings} (actives and promises) are
indicated as such.
\item Locked bindings get a \verb{[L]} tag
}
Note that printing a package namespace (see \code{\link[=ns_env]{ns_env()}}) with
\code{env_print()} will typically tag function bindings as \verb{}
until they are evaluated the first time. This is because package
functions are lazily-loaded from disk to improve performance when
loading a package.
}
rlang/man/dots_n.Rd 0000644 0001762 0000144 00000000653 14127057575 013726 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots.R
\name{dots_n}
\alias{dots_n}
\title{How many arguments are currently forwarded in dots?}
\usage{
dots_n(...)
}
\arguments{
\item{...}{Forwarded arguments.}
}
\description{
This returns the number of arguments currently forwarded in \code{...}
as an integer.
}
\examples{
fn <- function(...) dots_n(..., baz)
fn(foo, bar)
}
\keyword{internal}
rlang/man/as_string.Rd 0000644 0001762 0000144 00000003554 14127057575 014434 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sym.R
\name{as_string}
\alias{as_string}
\title{Cast symbol to string}
\usage{
as_string(x)
}
\arguments{
\item{x}{A string or symbol. If a string, the attributes are
removed, if any.}
}
\value{
A character vector of length 1.
}
\description{
\code{as_string()} converts \link[=sym]{symbols} to character strings.
}
\section{Unicode tags}{
Unlike \code{\link[base:name]{base::as.symbol()}} and \code{\link[base:name]{base::as.name()}}, \code{as_string()}
automatically transforms unicode tags such as \code{""} to the
proper UTF-8 character. This is important on Windows because:
\itemize{
\item R on Windows has no UTF-8 support, and uses native encoding instead.
\item The native encodings do not cover all Unicode characters. For
example, Western encodings do not support CKJ characters.
\item When a lossy UTF-8 -> native transformation occurs, uncovered
characters are transformed to an ASCII unicode tag like \code{""}.
\item Symbols are always encoded in native. This means that
transforming the column names of a data frame to symbols might be
a lossy operation.
\item This operation is very common in the tidyverse because of data
masking APIs like dplyr where data frames are transformed to
environments. While the names of a data frame are stored as a
character vector, the bindings of environments are stored as
symbols.
}
Because it reencodes the ASCII unicode tags to their UTF-8
representation, the string -> symbol -> string roundtrip is
more stable with \code{as_string()}.
}
\examples{
# Let's create some symbols:
foo <- quote(foo)
bar <- sym("bar")
# as_string() converts symbols to strings:
foo
as_string(foo)
typeof(bar)
typeof(as_string(bar))
}
\seealso{
\code{\link[=as_name]{as_name()}} for a higher-level variant of \code{as_string()}
that automatically unwraps quosures.
}
rlang/man/is_namespace.Rd 0000644 0001762 0000144 00000000456 14127057575 015070 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-special.R
\name{is_namespace}
\alias{is_namespace}
\title{Is an object a namespace environment?}
\usage{
is_namespace(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
Is an object a namespace environment?
}
rlang/man/dots_values.Rd 0000644 0001762 0000144 00000004027 14175213516 014757 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots.R
\name{dots_values}
\alias{dots_values}
\title{Evaluate dots with preliminary splicing}
\usage{
dots_values(
...,
.ignore_empty = c("trailing", "none", "all"),
.preserve_empty = FALSE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
}
\arguments{
\item{...}{Arguments to evaluate and process splicing operators.}
\item{.ignore_empty}{Whether to ignore empty arguments. Can be one
of \code{"trailing"}, \code{"none"}, \code{"all"}. If \code{"trailing"}, only the
last argument is ignored if it is empty.}
\item{.preserve_empty}{Whether to preserve the empty arguments that
were not ignored. If \code{TRUE}, empty arguments are stored with
\code{\link[=missing_arg]{missing_arg()}} values. If \code{FALSE} (the default) an error is
thrown when an empty argument is detected.}
\item{.homonyms}{How to treat arguments with the same name. The
default, \code{"keep"}, preserves these arguments. Set \code{.homonyms} to
\code{"first"} to only keep the first occurrences, to \code{"last"} to keep
the last occurrences, and to \code{"error"} to raise an informative
error and indicate what arguments have duplicated names.}
\item{.check_assign}{Whether to check for \verb{<-} calls. When \code{TRUE} a
warning recommends users to use \code{=} if they meant to match a
function parameter or wrap the \verb{<-} call in curly braces otherwise.
This ensures assignments are explicit.}
}
\description{
This is a tool for advanced users. It captures dots, processes
unquoting and splicing operators, and evaluates them. Unlike
\code{\link[=dots_list]{dots_list()}}, it does not flatten spliced objects, instead they
are attributed a \code{spliced} class (see \code{\link[=splice]{splice()}}). You can process
spliced objects manually, perhaps with a custom predicate (see
\code{\link[=flatten_if]{flatten_if()}}).
}
\examples{
dots <- dots_values(!!! list(1, 2), 3)
dots
# Flatten the objects marked as spliced:
flatten_if(dots, is_spliced)
}
\keyword{internal}
rlang/man/local_error_call.Rd 0000644 0001762 0000144 00000011210 14175213516 015715 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{local_error_call}
\alias{local_error_call}
\title{Set local error call in an execution environment}
\usage{
local_error_call(call, frame = caller_env())
}
\arguments{
\item{call}{This can be:
\itemize{
\item A call to be used as context for an error thrown in that
execution environment.
\item The \code{NULL} value to show no context.
\item An execution environment, e.g. as returned by \code{\link[=caller_env]{caller_env()}}.
The \code{\link[=sys.call]{sys.call()}} for that environment is taken as context.
}}
\item{frame}{The execution environment in which to set the local
error call.}
}
\description{
\code{local_error_call()} is an alternative to explicitly passing a
\code{call} argument to \code{\link[=abort]{abort()}}. It sets the call (or a value that
indicates where to find the call, see below) in a local binding
that is automatically picked up by \code{\link[=abort]{abort()}}.
}
\section{Motivation for setting local error calls}{
By default \code{\link[=abort]{abort()}} uses the function call of its caller as
context in error messages:\preformatted{foo <- function() abort("Uh oh.")
foo()
#> Error in `foo()`: Uh oh.
}
This is not always appropriate. For example a function that checks
an input on the behalf of another function should reference the
latter, not the former:\preformatted{arg_check <- function(arg,
error_arg = as_string(substitute(arg))) \{
abort(cli::format_error("\{.arg \{error_arg\}\} is failing."))
\}
foo <- function(x) arg_check(x)
foo()
#> Error in `arg_check()`: `x` is failing.
}
The mismatch is clear in the example above. \code{arg_check()} does not
have any \code{x} argument and so it is confusing to present
\code{arg_check()} as being the relevant context for the failure of the
\code{x} argument.
One way around this is to take a \code{call} or \code{error_call} argument
and pass it to \code{abort()}. Here we name this argument \code{error_call}
for consistency with \code{error_arg} which is prefixed because there is
an existing \code{arg} argument. In other situations, taking \code{arg} and
\code{call} arguments might be appropriate.\preformatted{arg_check <- function(arg,
error_arg = as_string(substitute(arg)),
error_call = caller_env()) \{
abort(
cli::format_error("\{.arg \{error_arg\}\} is failing."),
call = error_call
)
\}
foo <- function(x) arg_check(x)
foo()
#> Error in `foo()`: `x` is failing.
}
This is the generally recommended pattern for argument checking
functions. If you mention an argument in an error message, provide
your callers a way to supply a different argument name and a
different error call. \code{abort()} stores the error call in the \code{call}
condition field which is then used to generate the "in" part of
error messages.
In more complex cases it's often burdensome to pass the relevant
call around, for instance if your checking and throwing code is
structured into many different functions. In this case, use
\code{local_error_call()} to set the call locally or instruct \code{abort()}
to climb the call stack one level to find the relevant call. In the
following example, the complexity is not so important that sparing
the argument passing makes a big difference. However this
illustrates the pattern:\preformatted{arg_check <- function(arg,
error_arg = caller_arg(arg),
error_call = caller_env()) \{
# Set the local error call
local_error_call(error_call)
my_classed_stop(
cli::format_error("\{.arg \{error_arg\}\} is failing.")
)
\}
my_classed_stop <- function(message) \{
# Forward the local error call to the caller's
local_error_call(caller_env())
abort(message, class = "my_class")
\}
foo <- function(x) arg_check(x)
foo()
#> Error in `foo()`: `x` is failing.
}
}
\section{Error call flags in performance-critical functions}{
The \code{call} argument can also be the string \code{"caller"}. This is
equivalent to \code{caller_env()} or \code{parent.frame()} but has a lower
overhead because call stack introspection is only performed when an
error is triggered. Note that eagerly calling \code{caller_env()} is
fast enough in almost all cases.
If your function needs to be really fast, assign the error call
flag directly instead of calling \code{local_error_call()}:\preformatted{.__error_call__. <- "caller"
}
}
\examples{
# Set a context for error messages
function() {
local_error_call(quote(foo()))
local_error_call(sys.call())
}
# Disable the context
function() {
local_error_call(NULL)
}
# Use the caller's context
function() {
local_error_call(caller_env())
}
}
rlang/man/env_names.Rd 0000644 0001762 0000144 00000003254 14127057575 014413 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_names}
\alias{env_names}
\alias{env_length}
\title{Names and numbers of symbols bound in an environment}
\usage{
env_names(env)
env_length(env)
}
\arguments{
\item{env}{An environment.}
}
\value{
A character vector of object names.
}
\description{
\code{env_names()} returns object names from an enviroment \code{env} as a
character vector. All names are returned, even those starting with
a dot. \code{env_length()} returns the number of bindings.
}
\section{Names of symbols and objects}{
Technically, objects are bound to symbols rather than strings,
since the R interpreter evaluates symbols (see \code{\link[=is_expression]{is_expression()}} for a
discussion of symbolic objects versus literal objects). However it
is often more convenient to work with strings. In rlang
terminology, the string corresponding to a symbol is called the
\emph{name} of the symbol (or by extension the name of an object bound
to a symbol).
}
\section{Encoding}{
There are deep encoding issues when you convert a string to symbol
and vice versa. Symbols are \emph{always} in the native encoding. If
that encoding (let's say latin1) cannot support some characters,
these characters are serialised to ASCII. That's why you sometimes
see strings looking like \verb{}, especially if you're running
Windows (as R doesn't support UTF-8 as native encoding on that
platform).
To alleviate some of the encoding pain, \code{env_names()} always
returns a UTF-8 character vector (which is fine even on Windows)
with ASCII unicode points translated back to UTF-8.
}
\examples{
env <- env(a = 1, b = 2)
env_names(env)
}
rlang/man/missing.Rd 0000644 0001762 0000144 00000004434 14175213516 014102 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vec-na.R
\docType{data}
\name{missing}
\alias{missing}
\alias{na_lgl}
\alias{na_int}
\alias{na_dbl}
\alias{na_chr}
\alias{na_cpl}
\title{Missing values}
\format{
An object of class \code{logical} of length 1.
An object of class \code{integer} of length 1.
An object of class \code{numeric} of length 1.
An object of class \code{character} of length 1.
An object of class \code{complex} of length 1.
}
\usage{
na_lgl
na_int
na_dbl
na_chr
na_cpl
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#questioning}{\figure{lifecycle-questioning.svg}{options: alt='[Questioning]'}}}{\strong{[Questioning]}}
Missing values are represented in R with the general symbol
\code{NA}. They can be inserted in almost all data containers: all
atomic vectors except raw vectors can contain missing values. To
achieve this, R automatically converts the general \code{NA} symbol to a
typed missing value appropriate for the target vector. The objects
provided here are aliases for those typed \code{NA} objects.
}
\details{
Typed missing values are necessary because R needs sentinel values
of the same type (i.e. the same machine representation of the data)
as the containers into which they are inserted. The official typed
missing values are \code{NA_integer_}, \code{NA_real_}, \code{NA_character_} and
\code{NA_complex_}. The missing value for logical vectors is simply the
default \code{NA}. The aliases provided in rlang are consistently named
and thus simpler to remember. Also, \code{na_lgl} is provided as an
alias to \code{NA} that makes intent clearer.
Since \code{na_lgl} is the default \code{NA}, expressions such as \code{c(NA, NA)}
yield logical vectors as no data is available to give a clue of the
target type. In the same way, since lists and environments can
contain any types, expressions like \code{list(NA)} store a logical
\code{NA}.
}
\section{Life cycle}{
These shortcuts might be moved to the vctrs package at some
point. This is why they are marked as questioning.
}
\examples{
typeof(NA)
typeof(na_lgl)
typeof(na_int)
# Note that while the base R missing symbols cannot be overwritten,
# that's not the case for rlang's aliases:
na_dbl <- NA
typeof(na_dbl)
}
\keyword{datasets}
\keyword{internal}
rlang/man/list2.Rd 0000644 0001762 0000144 00000010310 14175213516 013454 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots.R
\name{list2}
\alias{list2}
\alias{ll}
\alias{dots_list}
\title{Collect dynamic dots in a list}
\usage{
list2(...)
dots_list(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.preserve_empty = FALSE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
}
\arguments{
\item{...}{Arguments to collect in a list. These dots are
\link[=dyn-dots]{dynamic}.}
\item{.named}{If \code{TRUE}, unnamed inputs are automatically named
with \code{\link[=as_label]{as_label()}}. This is equivalent to applying
\code{\link[=exprs_auto_name]{exprs_auto_name()}} on the result. If \code{FALSE}, unnamed elements
are left as is and, if fully unnamed, the list is given minimal
names (a vector of \code{""}). If \code{NULL}, fully unnamed results are
left with \code{NULL} names.}
\item{.ignore_empty}{Whether to ignore empty arguments. Can be one
of \code{"trailing"}, \code{"none"}, \code{"all"}. If \code{"trailing"}, only the
last argument is ignored if it is empty.}
\item{.preserve_empty}{Whether to preserve the empty arguments that
were not ignored. If \code{TRUE}, empty arguments are stored with
\code{\link[=missing_arg]{missing_arg()}} values. If \code{FALSE} (the default) an error is
thrown when an empty argument is detected.}
\item{.homonyms}{How to treat arguments with the same name. The
default, \code{"keep"}, preserves these arguments. Set \code{.homonyms} to
\code{"first"} to only keep the first occurrences, to \code{"last"} to keep
the last occurrences, and to \code{"error"} to raise an informative
error and indicate what arguments have duplicated names.}
\item{.check_assign}{Whether to check for \verb{<-} calls. When \code{TRUE} a
warning recommends users to use \code{=} if they meant to match a
function parameter or wrap the \verb{<-} call in curly braces otherwise.
This ensures assignments are explicit.}
}
\value{
A list containing the \code{...} inputs.
}
\description{
\code{list2(...)} is equivalent to \code{list(...)} with a few additional
features, collectively called \link[=dyn-dots]{dynamic dots}. While
\code{list2()} hard-code these features, \code{dots_list()} is a lower-level
version that offers more control.
}
\examples{
# Let's create a function that takes a variable number of arguments:
numeric <- function(...) {
dots <- list2(...)
num <- as.numeric(dots)
set_names(num, names(dots))
}
numeric(1, 2, 3)
# The main difference with list(...) is that list2(...) enables
# the `!!!` syntax to splice lists:
x <- list(2, 3)
numeric(1, !!! x, 4)
# As well as unquoting of names:
nm <- "yup!"
numeric(!!nm := 1)
# One useful application of splicing is to work around exact and
# partial matching of arguments. Let's create a function taking
# named arguments and dots:
fn <- function(data, ...) {
list2(...)
}
# You normally cannot pass an argument named `data` through the dots
# as it will match `fn`'s `data` argument. The splicing syntax
# provides a workaround:
fn("wrong!", data = letters) # exact matching of `data`
fn("wrong!", dat = letters) # partial matching of `data`
fn(some_data, !!!list(data = letters)) # no matching
# Empty arguments trigger an error by default:
try(fn(, ))
# You can choose to preserve empty arguments instead:
list3 <- function(...) dots_list(..., .preserve_empty = TRUE)
# Note how the last empty argument is still ignored because
# `.ignore_empty` defaults to "trailing":
list3(, )
# The list with preserved empty arguments is equivalent to:
list(missing_arg())
# Arguments with duplicated names are kept by default:
list2(a = 1, a = 2, b = 3, b = 4, 5, 6)
# Use the `.homonyms` argument to keep only the first of these:
dots_list(a = 1, a = 2, b = 3, b = 4, 5, 6, .homonyms = "first")
# Or the last:
dots_list(a = 1, a = 2, b = 3, b = 4, 5, 6, .homonyms = "last")
# Or raise an informative error:
try(dots_list(a = 1, a = 2, b = 3, b = 4, 5, 6, .homonyms = "error"))
# dots_list() can be configured to warn when a `<-` call is
# detected:
my_list <- function(...) dots_list(..., .check_assign = TRUE)
my_list(a <- 1)
# There is no warning if the assignment is wrapped in braces.
# This requires users to be explicit about their intent:
my_list({ a <- 1 })
}
rlang/man/topic-inject-out-of-context.Rd 0000644 0001762 0000144 00000007517 14175213516 017717 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic-nse.R
\name{topic-inject-out-of-context}
\alias{topic-inject-out-of-context}
\title{What happens if I use injection operators out of context?}
\description{
The \link[=topic-inject]{injection operators} \ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}}, \code{\link[=injection-operator]{!!}}, and \code{\link[=splice-operator]{!!!}} are an extension of the R syntax developed for tidyverse packages. Because they are not part of base R, they suffer from some limitations. In particular no specific error is thrown when they are used in unexpected places.
\subsection{Using \verb{\{\{} out of context}{
The embrace operator \ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}} is a feature available in \link[=topic-data-mask]{data-masked} arguments powered by tidy eval. If you use it elsewhere, it is interpreted as a double \verb{\{} wrapping.
In the R language, \verb{\{} is like \code{(} but takes multiple expressions instead of one:\if{html}{\out{
}}
So nothing prevents you from embracing a function argument in a context where this operation is not implemented. R will just treat the braces like a set of parentheses and silently return the result:\if{html}{\out{
}}
This sort of no-effect embracing should be avoided in real code because it falsely suggests that the function supports the tidy eval operator and that something special is happening.
However in many cases embracing is done to implement \link[=topic-data-mask]{data masking}. It is likely that the function will be called with data-variables references which R won't be able to resolve properly:\if{html}{\out{
}}\preformatted{my_mean <- function(data, var) \{
with(data, mean(\{\{ var \}\}))
\}
my_mean(mtcars, cyl)
#> Error in mean(\{: object 'cyl' not found
}\if{html}{\out{
}}
Since \code{\link[=with]{with()}} is a base data-masking function that doesn't support tidy eval operators, the embrace operator does not work and we get an object not found error.
}
\subsection{Using \verb{!!} and \verb{!!!} out of context}{
The injection operators \code{\link{!!}} and \code{\link{!!!}} are implemented in \link[=topic-data-mask]{data-masked} arguments, \link[=dyn-dots]{dynamic dots}, and within \code{\link[=inject]{inject()}}. When used in other contexts, they are interpreted by R as double and triple \emph{negations}.
Double negation can be used in ordinary code to convert an input to logical:\if{html}{\out{
}}
This means that when injection operators are used in the wrong place, they will be interpreted as negation. In the best case scenario you will get a type error:\if{html}{\out{
}}\preformatted{!"foo"
#> Error in !"foo": invalid argument type
!quote(foo)
#> Error in !quote(foo): invalid argument type
!quote(foo())
#> Error in !quote(foo()): invalid argument type
}\if{html}{\out{
}}
In the worst case, R will silently convert the input to logical. Unfortunately there is no systematic way of checking for these errors.
}
}
\keyword{internal}
rlang/man/new_quosure.Rd 0000644 0001762 0000144 00000003573 14175213516 015010 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/quo.R
\name{new_quosure}
\alias{new_quosure}
\alias{as_quosure}
\alias{is_quosure}
\title{Create a quosure from components}
\usage{
new_quosure(expr, env = caller_env())
as_quosure(x, env = NULL)
is_quosure(x)
}
\arguments{
\item{expr}{An expression to wrap in a quosure.}
\item{env}{The environment in which the expression should be
evaluated. Only used for symbols and calls. This should normally
be the environment in which the expression was created.}
\item{x}{An object to test.}
}
\description{
\itemize{
\item \code{new_quosure()} wraps any R object (including expressions,
formulas, or other quosures) into a \link[=topic-quosure]{quosure}.
\item \code{as_quosure()} is similar but it does not rewrap formulas and
quosures.
}
}
\examples{
# `new_quosure()` creates a quosure from its components. These are
# equivalent:
new_quosure(quote(foo), current_env())
quo(foo)
# `new_quosure()` always rewraps its input into a new quosure, even
# if the input is itself a quosure:
new_quosure(quo(foo))
# This is unlike `as_quosure()` which preserves its input if it's
# already a quosure:
as_quosure(quo(foo))
# `as_quosure()` uses the supplied environment with naked expressions:
env <- env(var = "thing")
as_quosure(quote(var), env)
# If the expression already carries an environment, this
# environment is preserved. This is the case for formulas and
# quosures:
as_quosure(~foo, env)
as_quosure(~foo)
# An environment must be supplied when the input is a naked
# expression:
try(
as_quosure(quote(var))
)
}
\seealso{
\itemize{
\item \code{\link[=enquo]{enquo()}} and \code{\link[=quo]{quo()}} for creating a quosure by \link[=topic-defuse]{argument defusal}.
\item \ifelse{html}{\link[=topic-quosure]{What are quosures and when are they needed?}}{\link[=topic-quosure]{What are quosures and when are they needed?}}
}
}
rlang/man/pairlist2.Rd 0000644 0001762 0000144 00000001441 14175213516 014335 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{pairlist2}
\alias{pairlist2}
\title{Collect dynamic dots in a pairlist}
\usage{
pairlist2(...)
}
\arguments{
\item{...}{<\link[=dyn-dots]{dynamic}> Arguments stored in the
pairlist. Empty arguments are preserved.}
}
\description{
This pairlist constructor uses \link[=dyn-dots]{dynamic dots}. Use
it to manually create argument lists for calls or parameter lists
for functions.
}
\examples{
# Unlike `exprs()`, `pairlist2()` evaluates its arguments.
new_function(pairlist2(x = 1, y = 3 * 6), quote(x * y))
new_function(exprs(x = 1, y = 3 * 6), quote(x * y))
# It preserves missing arguments, which is useful for creating
# parameters without defaults:
new_function(pairlist2(x = , y = 3 * 6), quote(x * y))
}
rlang/man/vector-construction.Rd 0000644 0001762 0000144 00000004115 14175213516 016457 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vec-new.R
\name{vector-construction}
\alias{vector-construction}
\alias{lgl}
\alias{int}
\alias{dbl}
\alias{cpl}
\alias{chr}
\alias{bytes}
\title{Create vectors}
\usage{
lgl(...)
int(...)
dbl(...)
cpl(...)
chr(...)
bytes(...)
}
\arguments{
\item{...}{Components of the new vector. Bare lists and explicitly
spliced lists are spliced.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#questioning}{\figure{lifecycle-questioning.svg}{options: alt='[Questioning]'}}}{\strong{[Questioning]}}
The atomic vector constructors are equivalent to \code{\link[=c]{c()}} but:
\itemize{
\item They allow you to be more explicit about the output
type. Implicit coercions (e.g. from integer to logical) follow
the rules described in \link{vector-coercion}.
\item They use \link[=dyn-dots]{dynamic dots}.
}
}
\section{Life cycle}{
\itemize{
\item All the abbreviated constructors such as \code{lgl()} will probably be
moved to the vctrs package at some point. This is why they are
marked as questioning.
\item Automatic splicing is soft-deprecated and will trigger a warning
in a future version. Please splice explicitly with \verb{!!!}.
}
}
\examples{
# These constructors are like a typed version of c():
c(TRUE, FALSE)
lgl(TRUE, FALSE)
# They follow a restricted set of coercion rules:
int(TRUE, FALSE, 20)
# Lists can be spliced:
dbl(10, !!! list(1, 2L), TRUE)
# They splice names a bit differently than c(). The latter
# automatically composes inner and outer names:
c(a = c(A = 10), b = c(B = 20, C = 30))
# On the other hand, rlang's ctors use the inner names and issue a
# warning to inform the user that the outer names are ignored:
dbl(a = c(A = 10), b = c(B = 20, C = 30))
dbl(a = c(1, 2))
# As an exception, it is allowed to provide an outer name when the
# inner vector is an unnamed scalar atomic:
dbl(a = 1)
# Spliced lists behave the same way:
dbl(!!! list(a = 1))
dbl(!!! list(a = c(A = 1)))
# bytes() accepts integerish inputs
bytes(1:10)
bytes(0x01, 0xff, c(0x03, 0x05), list(10, 20, 30L))
}
rlang/man/quo_label.Rd 0000644 0001762 0000144 00000005455 14175213516 014400 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/quo.R
\name{quo_label}
\alias{quo_label}
\alias{quo_text}
\alias{quo_name}
\title{Format quosures for printing or labelling}
\usage{
quo_label(quo)
quo_text(quo, width = 60L, nlines = Inf)
quo_name(quo)
}
\arguments{
\item{quo}{A quosure or expression.}
\item{width}{Width of each line.}
\item{nlines}{Maximum number of lines to extract.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#questioning}{\figure{lifecycle-questioning.svg}{options: alt='[Questioning]'}}}{\strong{[Questioning]}}
\strong{Note:} You should now use \code{\link[=as_label]{as_label()}} or \code{\link[=as_name]{as_name()}} instead
of \code{quo_name()}. See life cycle section below.
These functions take an arbitrary R object, typically an
\link[=is_expression]{expression}, and represent it as a string.
\itemize{
\item \code{quo_name()} returns an abbreviated representation of the object
as a single line string. It is suitable for default names.
\item \code{quo_text()} returns a multiline string. For instance block
expressions like \code{{ foo; bar }} are represented on 4 lines (one
for each symbol, and the curly braces on their own lines).
}
These deparsers are only suitable for creating default names or
printing output at the console. The behaviour of your functions
should not depend on deparsed objects. If you are looking for a way
of transforming symbols to strings, use \code{\link[=as_string]{as_string()}} instead of
\code{quo_name()}. Unlike deparsing, the transformation between symbols
and strings is non-lossy and well defined.
}
\section{Life cycle}{
These functions are in the questioning life cycle stage.
\itemize{
\item \code{\link[=as_label]{as_label()}} and \code{\link[=as_name]{as_name()}} should be used instead of
\code{quo_name()}. \code{as_label()} transforms any R object to a string
but should only be used to create a default name. Labelisation is
not a well defined operation and no assumption should be made
about the label. On the other hand, \code{as_name()} only works with
(possibly quosured) symbols, but is a well defined and
deterministic operation.
\item We don't have a good replacement for \code{quo_text()} yet. See
\url{https://github.com/r-lib/rlang/issues/636} to follow discussions
about a new deparsing API.
}
}
\examples{
# Quosures can contain nested quosures:
quo <- quo(foo(!! quo(bar)))
quo
# quo_squash() unwraps all quosures and returns a raw expression:
quo_squash(quo)
# This is used by quo_text() and quo_label():
quo_text(quo)
# Compare to the unwrapped expression:
expr_text(quo)
# quo_name() is helpful when you need really short labels:
quo_name(quo(sym))
quo_name(quo(!! sym))
}
\seealso{
\code{\link[=expr_label]{expr_label()}}, \code{\link[=f_label]{f_label()}}
}
\keyword{internal}
rlang/man/embrace-operator.Rd 0000644 0001762 0000144 00000002474 14175213516 015662 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-defuse.R
\name{embrace-operator}
\alias{embrace-operator}
\alias{curly-curly}
\title{Embrace operator \verb{\{\{}}
\description{
The embrace operator \verb{\{\{} is used to create functions that call
other \link[=topic-data-mask]{data-masking} functions. It transports a
data-masked argument (an argument that can refer to columns of a
data frame) from one function to another.\if{html}{\out{
}}\preformatted{my_mean <- function(data, var) \{
dplyr::summarise(data, mean = mean(\{\{ var \}\}))
\}
}\if{html}{\out{
}}
}
\section{Under the hood}{
\verb{\{\{} combines \code{\link[=enquo]{enquo()}} and \code{\link[=injection-operator]{!!}} in one
step. The snippet above is equivalent to:\if{html}{\out{
}}\preformatted{my_mean <- function(data, var) \{
var <- enquo(var)
dplyr::summarise(data, mean = mean(!!var))
\}
}\if{html}{\out{
}}
}
\seealso{
\itemize{
\item \ifelse{html}{\link[=topic-data-mask]{What is data-masking and why do I need \{\{?}}{\link[=topic-data-mask]{What is data-masking and why do I need curly-curly?}}
\item \ifelse{html}{\link[=topic-data-mask-programming]{Data mask programming patterns}}{\link[=topic-data-mask-programming]{Data mask programming patterns}}
}
}
rlang/man/has_length.Rd 0000644 0001762 0000144 00000001361 14127057575 014551 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/attr.R
\name{has_length}
\alias{has_length}
\title{How long is an object?}
\usage{
has_length(x, n = NULL)
}
\arguments{
\item{x}{A R object.}
\item{n}{A specific length to test \code{x} with. If \code{NULL},
\code{has_length()} returns \code{TRUE} if \code{x} has length greater than
zero, and \code{FALSE} otherwise.}
}
\description{
This is a function for the common task of testing the length of an
object. It checks the length of an object in a non-generic way:
\code{\link[base:length]{base::length()}} methods are ignored.
}
\examples{
has_length(list())
has_length(list(), 0)
has_length(letters)
has_length(letters, 20)
has_length(letters, 26)
}
\keyword{internal}
rlang/man/topic-embrace-non-args.Rd 0000644 0001762 0000144 00000003132 14175213516 016657 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic-nse.R
\name{topic-embrace-non-args}
\alias{topic-embrace-non-args}
\title{Does \verb{\{\{} work on regular objects?}
\description{
The embrace operator \ifelse{html}{\code{\link[=embrace-operator]{\{\{}}}{\verb{\{\{}} should be used exclusively with function arguments:\if{html}{\out{
}}
In that case, \verb{\{\{} captures the \emph{value} of the expression instead of a defused expression. That's because only function arguments can be defused.
Note that this issue also applies to \code{\link[=enquo]{enquo()}} (on which \verb{\{\{} is based).
}
\section{Why is this not an error?}{
Ideally we would have made \verb{\{\{} on regular objects an error. However this is not possible because in compiled R code it is not always possible to distinguish a regular variable from a function argument. See \ifelse{html}{\link[=topic-embrace-constants]{Why are strings and other constants enquosed in the empty environment?}}{\link[=topic-embrace-constants]{Why are strings and other constants enquosed in the empty environment?}} for more about this.
}
\keyword{internal}
rlang/man/wref_key.Rd 0000644 0001762 0000144 00000000663 14127057575 014254 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/weakref.R
\name{wref_key}
\alias{wref_key}
\alias{wref_value}
\title{Get key/value from a weak reference object}
\usage{
wref_key(x)
wref_value(x)
}
\arguments{
\item{x}{A weak reference object.}
}
\description{
Get key/value from a weak reference object
}
\seealso{
\code{\link[=is_weakref]{is_weakref()}} and \code{\link[=new_weakref]{new_weakref()}}.
}
rlang/man/bare-type-predicates.Rd 0000644 0001762 0000144 00000003033 14175213516 016434 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{bare-type-predicates}
\alias{bare-type-predicates}
\alias{is_bare_list}
\alias{is_bare_atomic}
\alias{is_bare_vector}
\alias{is_bare_double}
\alias{is_bare_complex}
\alias{is_bare_integer}
\alias{is_bare_numeric}
\alias{is_bare_character}
\alias{is_bare_logical}
\alias{is_bare_raw}
\alias{is_bare_string}
\alias{is_bare_bytes}
\title{Bare type predicates}
\usage{
is_bare_list(x, n = NULL)
is_bare_atomic(x, n = NULL)
is_bare_vector(x, n = NULL)
is_bare_double(x, n = NULL)
is_bare_complex(x, n = NULL)
is_bare_integer(x, n = NULL)
is_bare_numeric(x, n = NULL)
is_bare_character(x, n = NULL)
is_bare_logical(x, n = NULL)
is_bare_raw(x, n = NULL)
is_bare_string(x, n = NULL)
is_bare_bytes(x, n = NULL)
}
\arguments{
\item{x}{Object to be tested.}
\item{n}{Expected length of a vector.}
}
\description{
These predicates check for a given type but only return \code{TRUE} for
bare R objects. Bare objects have no class attributes. For example,
a data frame is a list, but not a bare list.
}
\details{
\itemize{
\item The predicates for vectors include the \code{n} argument for
pattern-matching on the vector length.
\item Like \code{\link[=is_atomic]{is_atomic()}} and unlike base R \code{is.atomic()},
\code{is_bare_atomic()} does not return \code{TRUE} for \code{NULL}.
\item Unlike base R \code{is.numeric()}, \code{is_bare_double()} only returns
\code{TRUE} for floating point numbers.
}
}
\seealso{
\link{type-predicates}, \link{scalar-type-predicates}
}
rlang/man/interrupt.Rd 0000644 0001762 0000144 00000000607 14175213516 014463 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-signal.R
\name{interrupt}
\alias{interrupt}
\title{Simulate interrupt condition}
\usage{
interrupt()
}
\description{
\code{interrupt()} simulates a user interrupt of the kind that is
signalled with \code{Ctrl-C}. It is currently not possible to create
custom interrupt condition objects.
}
\keyword{internal}
rlang/man/as_box.Rd 0000644 0001762 0000144 00000001477 14127057575 013720 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s3.R
\name{as_box}
\alias{as_box}
\alias{as_box_if}
\title{Convert object to a box}
\usage{
as_box(x, class = NULL)
as_box_if(.x, .p, .class = NULL, ...)
}
\arguments{
\item{x}{An R object.}
\item{class, .class}{A box class. If the input is already a box of
that class, it is returned as is. If the input needs to be boxed,
\code{class} is passed to \code{\link[=new_box]{new_box()}}.}
\item{.x}{An R object.}
\item{.p}{A predicate function.}
\item{...}{Arguments passed to \code{.p}.}
}
\description{
\itemize{
\item \code{as_box()} boxes its input only if it is not already a box. The
class is also checked if supplied.
\item \code{as_box_if()} boxes its input only if it not already a box, or if
the predicate \code{.p} returns \code{TRUE}.
}
}
rlang/man/inherits_any.Rd 0000644 0001762 0000144 00000003042 14127057575 015127 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s3.R
\name{inherits_any}
\alias{inherits_any}
\alias{inherits_all}
\alias{inherits_only}
\title{Does an object inherit from a set of classes?}
\usage{
inherits_any(x, class)
inherits_all(x, class)
inherits_only(x, class)
}
\arguments{
\item{x}{An object to test for inheritance.}
\item{class}{A character vector of classes.}
}
\description{
\itemize{
\item \code{inherits_any()} is like \code{\link[base:class]{base::inherits()}} but is more explicit
about its behaviour with multiple classes. If \code{classes} contains
several elements and the object inherits from at least one of
them, \code{inherits_any()} returns \code{TRUE}.
\item \code{inherits_all()} tests that an object inherits from all of the
classes in the supplied order. This is usually the best way to
test for inheritance of multiple classes.
\item \code{inherits_only()} tests that the class vectors are identical. It
is a shortcut for \code{identical(class(x), class)}.
}
}
\examples{
obj <- structure(list(), class = c("foo", "bar", "baz"))
# With the _any variant only one class must match:
inherits_any(obj, c("foobar", "bazbaz"))
inherits_any(obj, c("foo", "bazbaz"))
# With the _all variant all classes must match:
inherits_all(obj, c("foo", "bazbaz"))
inherits_all(obj, c("foo", "baz"))
# The order of classes must match as well:
inherits_all(obj, c("baz", "foo"))
# inherits_only() checks that the class vectors are identical:
inherits_only(obj, c("foo", "baz"))
inherits_only(obj, c("foo", "bar", "baz"))
}
rlang/man/env_lock.Rd 0000644 0001762 0000144 00000002763 14175213516 014234 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{env_lock}
\alias{env_lock}
\alias{env_is_locked}
\title{Lock an environment}
\usage{
env_lock(env)
env_is_locked(env)
}
\arguments{
\item{env}{An environment.}
}
\value{
The old value of \code{env_is_locked()} invisibly.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Locked environments cannot be modified. An important example is
namespace environments which are locked by R when loaded in a
session. Once an environment is locked it normally cannot be
unlocked.
Note that only the environment as a container is locked, not the
individual bindings. You can't remove or add a binding but you can
still modify the values of existing bindings. See
\code{\link[=env_binding_lock]{env_binding_lock()}} for locking individual bindings.
}
\examples{
# New environments are unlocked by default:
env <- env(a = 1)
env_is_locked(env)
# Use env_lock() to lock them:
env_lock(env)
env_is_locked(env)
# Now that `env` is locked, it is no longer possible to remove or
# add bindings. If run, the following would fail:
# env_unbind(env, "a")
# env_bind(env, b = 2)
# Note that even though the environment as a container is locked,
# the individual bindings are still unlocked and can be modified:
env$a <- 10
}
\seealso{
\code{\link[=env_binding_lock]{env_binding_lock()}}
}
\keyword{internal}
rlang/man/env_clone.Rd 0000644 0001762 0000144 00000001125 14175213516 014373 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{env_clone}
\alias{env_clone}
\title{Clone an environment}
\usage{
env_clone(env, parent = env_parent(env))
}
\arguments{
\item{env}{An environment.}
\item{parent}{The parent of the cloned environment.}
}
\description{
This creates a new environment containing exactly the same objects,
optionally with a new parent. Active bindings and promises are
preserved (the latter only on R >= 4.0.0).
}
\examples{
env <- env(!!! mtcars)
clone <- env_clone(env)
identical(env, clone)
identical(env$cyl, clone$cyl)
}
rlang/man/with_env.Rd 0000644 0001762 0000144 00000004057 14175213516 014255 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{with_env}
\alias{with_env}
\alias{locally}
\title{Evaluate an expression within a given environment}
\usage{
with_env(env, expr)
locally(expr)
}
\arguments{
\item{env}{An environment within which to evaluate \code{expr}. Can be
an object with a \code{\link[=get_env]{get_env()}} method.}
\item{expr}{An expression to evaluate.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
These functions evaluate \code{expr} within a given environment (\code{env}
for \code{with_env()}, or the child of the current environment for
\code{locally}). They rely on \code{\link[=eval_bare]{eval_bare()}} which features a lighter
evaluation mechanism than base R \code{\link[base:eval]{base::eval()}}, and which also has
some subtle implications when evaluting stack sensitive functions
(see help for \code{\link[=eval_bare]{eval_bare()}}).
\code{locally()} is equivalent to the base function
\code{\link[base:eval]{base::local()}} but it produces a much cleaner
evaluation stack, and has stack-consistent semantics. It is thus
more suited for experimenting with the R language.
}
\examples{
# with_env() is handy to create formulas with a given environment:
env <- child_env("rlang")
f <- with_env(env, ~new_formula())
identical(f_env(f), env)
# Or functions with a given enclosure:
fn <- with_env(env, function() NULL)
identical(get_env(fn), env)
# Unlike eval() it doesn't create duplicates on the evaluation
# stack. You can thus use it e.g. to create non-local returns:
fn <- function() {
g(current_env())
"normal return"
}
g <- function(env) {
with_env(env, return("early return"))
}
fn()
# Since env is passed to as_environment(), it can be any object with an
# as_environment() method. For strings, the pkg_env() is returned:
with_env("base", ~mtcars)
# This can be handy to put dictionaries in scope:
with_env(mtcars, cyl)
}
\keyword{internal}
rlang/man/caller_arg.Rd 0000644 0001762 0000144 00000002137 14175213516 014522 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{caller_arg}
\alias{caller_arg}
\title{Find the caller argument for error messages}
\arguments{
\item{arg}{An argument name in the current function.}
}
\description{
\code{caller_arg()} is a variant of \code{substitute()} or \code{\link[=ensym]{ensym()}} for
arguments that reference other arguments. Unlike \code{substitute()}
which returns an expression, \code{caller_arg()} formats the expression
as a single line string which can be included in error messages.
\itemize{
\item When included in an error message, the resulting label should
generally be formatted as argument, for instance using the \code{.arg}
in the cli package.
\item Use \verb{@inheritParams rlang::args_error_context} to document an
\code{arg} or \code{error_arg} argument that takes \code{error_arg()} as default.
}
}
\examples{
arg_checker <- function(x, arg = caller_arg(x), call = caller_env()) {
cli::cli_abort("{.arg arg} must be a thingy.", call = call)
}
my_function <- function(my_arg) {
arg_checker(my_arg)
}
try(my_function(NULL))
}
rlang/man/check_exclusive.Rd 0000644 0001762 0000144 00000003176 14175213516 015577 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg.R
\name{check_exclusive}
\alias{check_exclusive}
\title{Check that arguments are mutually exclusive}
\usage{
check_exclusive(
...,
.require = TRUE,
.frame = caller_env(),
.error_call = .frame
)
}
\arguments{
\item{...}{Function arguments.}
\item{.require}{Whether at least one argument must be supplied.}
\item{.frame}{Environment where the arguments in \code{...} are defined.}
\item{.error_call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\value{
The supplied argument name as a string. If \code{.require} is
\code{FALSE} and no argument is supplied, the empty string \code{""} is
returned.
}
\description{
\code{check_exclusive()} checks that only one argument is supplied out of
a set of mutually exclusive arguments. An informative error is
thrown if multiple arguments are supplied.
}
\examples{
f <- function(x, y) {
switch(
check_exclusive(x, y),
x = message("`x` was supplied."),
y = message("`y` was supplied.")
)
}
# Supplying zero or multiple arguments is forbidden
try(f())
try(f(NULL, NULL))
# The user must supply one of the mutually exclusive arguments
f(NULL)
f(y = NULL)
# With `.require` you can allow zero arguments
f <- function(x, y) {
switch(
check_exclusive(x, y, .require = FALSE),
x = message("`x` was supplied."),
y = message("`y` was supplied."),
message("No arguments were supplied")
)
}
f()
}
rlang/man/type_of.Rd 0000644 0001762 0000144 00000003214 14175213516 014071 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{type_of}
\alias{type_of}
\title{Base type of an object}
\usage{
type_of(x)
}
\arguments{
\item{x}{An R object.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#soft-deprecated}{\figure{lifecycle-soft-deprecated.svg}{options: alt='[Soft-deprecated]'}}}{\strong{[Soft-deprecated]}}
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
This is equivalent to \code{\link[base:typeof]{base::typeof()}} with a few differences that
make dispatching easier:
\itemize{
\item The type of one-sided formulas is "quote".
\item The type of character vectors of length 1 is "string".
\item The type of special and builtin functions is "primitive".
}
}
\examples{
type_of(10L)
# Quosures are treated as a new base type but not formulas:
type_of(quo(10L))
type_of(~10L)
# Compare to base::typeof():
typeof(quo(10L))
# Strings are treated as a new base type:
type_of(letters)
type_of(letters[[1]])
# This is a bit inconsistent with the core language tenet that data
# types are vectors. However, treating strings as a different
# scalar type is quite helpful for switching on function inputs
# since so many arguments expect strings:
switch_type("foo", character = abort("vector!"), string = "result")
# Special and builtin primitives are both treated as primitives.
# That's because it is often irrelevant which type of primitive an
# input is:
typeof(list)
typeof(`$`)
type_of(list)
type_of(`$`)
}
\keyword{internal}
rlang/man/type-predicates.Rd 0000644 0001762 0000144 00000003232 14175213516 015526 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.R
\name{type-predicates}
\alias{type-predicates}
\alias{is_list}
\alias{is_atomic}
\alias{is_vector}
\alias{is_integer}
\alias{is_double}
\alias{is_complex}
\alias{is_character}
\alias{is_logical}
\alias{is_raw}
\alias{is_bytes}
\alias{is_null}
\title{Type predicates}
\usage{
is_list(x, n = NULL)
is_atomic(x, n = NULL)
is_vector(x, n = NULL)
is_integer(x, n = NULL)
is_double(x, n = NULL, finite = NULL)
is_complex(x, n = NULL, finite = NULL)
is_character(x, n = NULL)
is_logical(x, n = NULL)
is_raw(x, n = NULL)
is_bytes(x, n = NULL)
is_null(x)
}
\arguments{
\item{x}{Object to be tested.}
\item{n}{Expected length of a vector.}
\item{finite}{Whether all values of the vector are finite. The
non-finite values are \code{NA}, \code{Inf}, \code{-Inf} and \code{NaN}. Setting this
to something other than \code{NULL} can be expensive because the whole
vector needs to be traversed and checked.}
}
\description{
These type predicates aim to make type testing in R more
consistent. They are wrappers around \code{\link[base:typeof]{base::typeof()}}, so operate
at a level beneath S3/S4 etc.
}
\details{
Compared to base R functions:
\itemize{
\item The predicates for vectors include the \code{n} argument for
pattern-matching on the vector length.
\item Unlike \code{is.atomic()}, \code{is_atomic()} does not return \code{TRUE} for
\code{NULL}.
\item Unlike \code{is.vector()}, \code{is_vector()} tests if an object is an
atomic vector or a list. \code{is.vector} checks for the presence of
attributes (other than name).
}
}
\seealso{
\link{bare-type-predicates} \link{scalar-type-predicates}
}
rlang/man/as_function.Rd 0000644 0001762 0000144 00000003666 14175213516 014747 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{as_function}
\alias{as_function}
\alias{is_lambda}
\title{Convert to function}
\usage{
as_function(
x,
env = global_env(),
...,
arg = caller_arg(x),
call = caller_env()
)
is_lambda(x)
}
\arguments{
\item{x}{A function or formula.
If a \strong{function}, it is used as is.
If a \strong{formula}, e.g. \code{~ .x + 2}, it is converted to a function
with up to two arguments: \code{.x} (single argument) or \code{.x} and \code{.y}
(two arguments). The \code{.} placeholder can be used instead of \code{.x}.
This allows you to create very compact anonymous functions (lambdas) with up
to two inputs. Functions created from formulas have a special
class. Use \code{is_lambda()} to test for it.
If a \strong{string}, the function is looked up in \code{env}. Note that
this interface is strictly for user convenience because of the
scoping issues involved. Package developers should avoid
supplying functions by name and instead supply them by value.}
\item{env}{Environment in which to fetch the function in case \code{x}
is a string.}
\item{...}{These dots are for future extensions and must be empty.}
\item{arg}{An argument name as a string. This argument
will be mentioned in error messages as the input that is at the
origin of a problem.}
\item{call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\description{
\code{as_function()} transforms a one-sided formula into a function.
This powers the lambda syntax in packages like purrr.
}
\examples{
f <- as_function(~ .x + 1)
f(10)
g <- as_function(~ -1 * .)
g(4)
h <- as_function(~ .x - .y)
h(6, 3)
# Functions created from a formula have a special class:
is_lambda(f)
is_lambda(as_function(function() "foo"))
}
rlang/man/trace_back.Rd 0000644 0001762 0000144 00000006752 14175213516 014514 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/trace.R
\name{trace_back}
\alias{trace_back}
\alias{trace_length}
\title{Capture a backtrace}
\usage{
trace_back(top = NULL, bottom = NULL)
trace_length(trace)
}
\arguments{
\item{top}{The first frame environment to be included in the
backtrace. This becomes the top of the backtrace tree and
represents the oldest call in the backtrace.
This is needed in particular when you call \code{trace_back()}
indirectly or from a larger context, for example in tests or
inside an RMarkdown document where you don't want all of the
knitr evaluation mechanisms to appear in the backtrace.
If not supplied, the \code{rlang_trace_top_env} global option is
consulted. This makes it possible to trim the embedding context
for all backtraces created while the option is set. If knitr is
in progress, the default value for this option is
\code{knitr::knit_global()} so that the knitr context is trimmed out
of backtraces.}
\item{bottom}{The last frame environment to be included in the
backtrace. This becomes the rightmost leaf of the backtrace tree
and represents the youngest call in the backtrace.
Set this when you would like to capture a backtrace without the
capture context.
Can also be an integer that will be passed to \code{\link[=caller_env]{caller_env()}}.}
\item{trace}{A backtrace created by \code{trace_back()}.}
}
\description{
A backtrace captures the sequence of calls that lead to the current
function (sometimes called the call stack). Because of lazy
evaluation, the call stack in R is actually a tree, which the
\code{print()} method for this object will reveal.
Users rarely need to call \code{trace_back()} manually. Instead,
signalling an error with \code{\link[=abort]{abort()}} or setting up \code{\link[=global_entrace]{global_entrace()}}
is the most common way to create backtraces when an error is
thrown. Inspect the backtrace created for the most recent error
with \code{\link[=last_error]{last_error()}}.
\code{trace_length()} returns the number of frames in a backtrace.
}
\examples{
# Trim backtraces automatically (this improves the generated
# documentation for the rlang website and the same trick can be
# useful within knitr documents):
options(rlang_trace_top_env = current_env())
f <- function() g()
g <- function() h()
h <- function() trace_back()
# When no lazy evaluation is involved the backtrace is linear
# (i.e. every call has only one child)
f()
# Lazy evaluation introduces a tree like structure
identity(identity(f()))
identity(try(f()))
try(identity(f()))
# When printing, you can request to simplify this tree to only show
# the direct sequence of calls that lead to `trace_back()`
x <- try(identity(f()))
x
print(x, simplify = "branch")
# With a little cunning you can also use it to capture the
# tree from within a base NSE function
x <- NULL
with(mtcars, {x <<- f(); 10})
x
# Restore default top env for next example
options(rlang_trace_top_env = NULL)
# When code is executed indirectly, i.e. via source or within an
# RMarkdown document, you'll tend to get a lot of guff at the beginning
# related to the execution environment:
conn <- textConnection("summary(f())")
source(conn, echo = TRUE, local = TRUE)
close(conn)
# To automatically strip this off, specify which frame should be
# the top of the backtrace. This will automatically trim off calls
# prior to that frame:
top <- current_env()
h <- function() trace_back(top)
conn <- textConnection("summary(f())")
source(conn, echo = TRUE, local = TRUE)
close(conn)
}
rlang/man/call_match.Rd 0000644 0001762 0000144 00000004646 14175213516 014525 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call_match}
\alias{call_match}
\title{Match supplied arguments to function definition}
\usage{
call_match(
call = NULL,
fn = NULL,
...,
defaults = FALSE,
dots_env = NULL,
dots_expand = TRUE
)
}
\arguments{
\item{call}{A call. The arguments will be matched to \code{fn}.}
\item{fn}{A function definition to match arguments to.}
\item{...}{These dots must be empty.}
\item{defaults}{Whether to match missing arguments to their
defaults.}
\item{dots_env}{An execution environment where to find dots. If
supplied and dots exist in this environment, and if \code{call}
includes \code{...}, the forwarded dots are matched to numbered dots
(e.g. \code{..1}, \code{..2}, etc). By default this is set to the empty
environment which means that \code{...} expands to nothing.}
\item{dots_expand}{If \code{FALSE}, arguments passed through \code{...} will
not be spliced into \code{call}. Instead, they are gathered in a
pairlist and assigned to an argument named \code{...}. Gathering dots
arguments is useful if you need to separate them from the other
named arguments.
Note that the resulting call is not meant to be evaluated since R
does not support passing dots through a named argument, even if
named \code{"..."}.}
}
\description{
\code{call_match()} is like \code{\link[=match.call]{match.call()}} with these differences:
\itemize{
\item It supports matching missing argument to their defaults in the
function definition.
\item It requires you to be a little more specific in some cases.
Either all arguments are inferred from the call stack or none of
them are (see the Inference section).
}
}
\section{Inference from the call stack}{
When \code{call} is not supplied, it is inferred from the call stack
along with \code{fn} and \code{dots_env}.
\itemize{
\item \code{call} and \code{fn} are inferred from the calling environment:
\code{sys.call(sys.parent())} and \code{sys.function(sys.parent())}.
\item \code{dots_env} is inferred from the caller of the calling
environment: \code{caller_env(2)}.
}
If \code{call} is supplied, then you must supply \code{fn} as well. Also
consider supplying \code{dots_env} as it is set to the empty environment
when not inferred.
}
\examples{
# `call_match()` supports matching missing arguments to their
# defaults
fn <- function(x = "default") fn
call_match(quote(fn()), fn)
call_match(quote(fn()), fn, defaults = TRUE)
}
rlang/man/args_error_context.Rd 0000644 0001762 0000144 00000002416 14175213516 016340 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.R
\name{args_error_context}
\alias{args_error_context}
\title{Documentation anchor for error arguments}
\arguments{
\item{arg, error_arg}{An argument name as a string. This argument
will be mentioned in error messages as the input that is at the
origin of a problem.}
\item{call, error_call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
}
\description{
Use \verb{@inheritParams rlang::args_error_context} in your package to
document \code{arg} and \code{call} arguments (or equivalently their prefixed
versions \code{error_arg} and \code{error_call}).
\itemize{
\item \code{arg} parameters should be formatted as argument (e.g. using
cli's \code{.arg} specifier) and included in error messages. See also
\code{\link[=caller_arg]{caller_arg()}}.
\item \code{call} parameters should be included in error conditions in a
field named \code{call}. An easy way to do this is by passing a \code{call}
argument to \code{\link[=abort]{abort()}}. See also \code{\link[=local_error_call]{local_error_call()}}.
}
}
rlang/man/as_utf8_character.Rd 0000644 0001762 0000144 00000003511 14175213516 016011 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-encoding.R
\name{as_utf8_character}
\alias{as_utf8_character}
\title{Coerce to a character vector and attempt encoding conversion}
\usage{
as_utf8_character(x)
}
\arguments{
\item{x}{An object to coerce.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Unlike specifying the \code{encoding} argument in \code{as_string()} and
\code{as_character()}, which is only declarative, these functions
actually attempt to convert the encoding of their input. There are
two possible cases:
\itemize{
\item The string is tagged as UTF-8 or latin1, the only two encodings
for which R has specific support. In this case, converting to the
same encoding is a no-op, and converting to native always works
as expected, as long as the native encoding, the one specified by
the \code{LC_CTYPE} locale has support for all characters occurring in
the strings. Unrepresentable characters are serialised as unicode
points: "".
\item The string is not tagged. R assumes that it is encoded in the
native encoding. Conversion to native is a no-op, and conversion
to UTF-8 should work as long as the string is actually encoded in
the locale codeset.
}
When translating to UTF-8, the strings are parsed for serialised
unicode points (e.g. strings looking like "U+xxxx") with
\code{\link[=chr_unserialise_unicode]{chr_unserialise_unicode()}}. This helps to alleviate the effects of
character-to-symbol-to-character roundtrips on systems with
non-UTF-8 native encoding.
}
\examples{
# Let's create a string marked as UTF-8 (which is guaranteed by the
# Unicode escaping in the string):
utf8 <- "caf\uE9"
Encoding(utf8)
charToRaw(utf8)
}
\keyword{internal}
rlang/man/env_has.Rd 0000644 0001762 0000144 00000001702 14127057575 014057 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_has}
\alias{env_has}
\title{Does an environment have or see bindings?}
\usage{
env_has(env = caller_env(), nms, inherit = FALSE)
}
\arguments{
\item{env}{An environment.}
\item{nms}{A character vector of binding names for which to check
existence.}
\item{inherit}{Whether to look for bindings in the parent
environments.}
}
\value{
A named logical vector as long as \code{nms}.
}
\description{
\code{env_has()} is a vectorised predicate that queries whether an
environment owns bindings personally (with \code{inherit} set to
\code{FALSE}, the default), or sees them in its own environment or in
any of its parents (with \code{inherit = TRUE}).
}
\examples{
parent <- child_env(NULL, foo = "foo")
env <- child_env(parent, bar = "bar")
# env does not own `foo` but sees it in its parent environment:
env_has(env, "foo")
env_has(env, "foo", inherit = TRUE)
}
rlang/man/topic-embrace-constants.Rd 0000644 0001762 0000144 00000006434 14175213516 017157 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/topic-nse.R
\name{topic-embrace-constants}
\alias{topic-embrace-constants}
\title{Why are strings and other constants enquosed in the empty environment?}
\description{
Function arguments are \link[=topic-defuse]{defused} into \link[=topic-quosure]{quosures} that keep track of the environment of the defused expression.\if{html}{\out{
}}
You might have noticed that when constants are supplied, the quosure tracks the empty environment instead of the current environmnent.\if{html}{\out{
}}
The reason for this has to do with compilation of R code which makes it impossible to consistently capture environments of constants from function arguments. Argument defusing relies on the \emph{promise} mechanism of R for lazy evaluation of arguments. When functions are compiled and R notices that an argument is constant, it avoids creating a promise since they slow down function evaluation. Instead, the function is directly supplied a naked constant instead of constant wrapped in a promise.
}
\section{Concrete case of promise unwrapping by compilation}{
We can observe this optimisation by calling into the C-level \code{findVar()} function to capture promises.\if{html}{\out{
}}\preformatted{# Return the object bound to `arg` without triggering evaluation of
# promises
f <- function(arg) \{
rlang:::find_var(current_env(), sym("arg"))
\}
# Call `f()` with a symbol or with a constant
g <- function(symbolic) \{
if (symbolic) \{
f(letters)
\} else \{
f("foo")
\}
\}
# Make sure these small functions are compiled
f <- compiler::cmpfun(f)
g <- compiler::cmpfun(g)
}\if{html}{\out{
}}
When \code{f()} is called with a symbolic argument, we get the promise object created by R.\if{html}{\out{
}}
Without a promise, there is no way to figure out the original environment of an argument.
}
\section{Do we need environments for constants?}{
Data-masking APIs in the tidyverse are intentionally designed so that they don't need an environment for constants.
\itemize{
\item Data-masking APIs should be able to interpret constants. These can arise from normal argument passing as we have seen, or by \link[=topic-inject]{injection} with \verb{!!}. There should be no difference between \code{dplyr::mutate(mtcars, var = cyl)} and \code{dplyr::mutate(mtcars, var = !!mtcars$cyl)}.
\item Data-masking is an \emph{evaluation} idiom, not an \emph{introspective} one. The behaviour of data-masking function should not depend on the calling environment when a constant (or a symbol evaluating to a given value) is supplied.
}
}
\keyword{internal}
rlang/man/cnd_muffle.Rd 0000644 0001762 0000144 00000005444 14127057575 014545 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-handlers.R
\name{cnd_muffle}
\alias{cnd_muffle}
\title{Muffle a condition}
\usage{
cnd_muffle(cnd)
}
\arguments{
\item{cnd}{A condition to muffle.}
}
\value{
If \code{cnd} is mufflable, \code{cnd_muffle()} jumps to the muffle
restart and doesn't return. Otherwise, it returns \code{FALSE}.
}
\description{
Unlike \code{\link[=exiting]{exiting()}} handlers, \code{\link[=calling]{calling()}} handlers must be explicit
that they have handled a condition to stop it from propagating to
other handlers. Use \code{cnd_muffle()} within a calling handler (or as
a calling handler, see examples) to prevent any other handlers from
being called for that condition.
}
\section{Mufflable conditions}{
Most conditions signalled by base R are muffable, although the name
of the restart varies. cnd_muffle() will automatically call the
correct restart for you. It is compatible with the following
conditions:
\itemize{
\item \code{warning} and \code{message} conditions. In this case \code{cnd_muffle()}
is equivalent to \code{\link[base:message]{base::suppressMessages()}} and
\code{\link[base:warning]{base::suppressWarnings()}}.
\item Bare conditions signalled with \code{signal()} or \code{\link[=cnd_signal]{cnd_signal()}}. Note
that conditions signalled with \code{\link[base:conditions]{base::signalCondition()}} are not
mufflable.
\item Interrupts are sometimes signalled with a \code{resume} restart on
recent R versions. When this is the case, you can muffle the
interrupt with \code{cnd_muffle()}. Check if a restart is available
with \code{base::findRestart("resume")}.
}
If you call \code{cnd_muffle()} with a condition that is not mufflable
you will cause a new error to be signalled.
\itemize{
\item Errors are not mufflable since they are signalled in critical
situations where execution cannot continue safely.
\item Conditions captured with \code{\link[base:conditions]{base::tryCatch()}}, \code{\link[=with_handlers]{with_handlers()}} or
\code{\link[=catch_cnd]{catch_cnd()}} are no longer mufflable. Muffling restarts \emph{must}
be called from a \link{calling} handler.
}
}
\examples{
fn <- function() {
inform("Beware!", "my_particular_msg")
inform("On your guard!")
"foobar"
}
# Let's install a muffling handler for the condition thrown by `fn()`.
# This will suppress all `my_particular_wng` warnings but let other
# types of warnings go through:
with_handlers(fn(),
my_particular_msg = calling(function(cnd) {
inform("Dealt with this particular message")
cnd_muffle(cnd)
})
)
# Note how execution of `fn()` continued normally after dealing
# with that particular message.
# cnd_muffle() can also be passed to with_handlers() as a calling
# handler:
with_handlers(fn(),
my_particular_msg = calling(cnd_muffle)
)
}
\keyword{internal}
rlang/man/call2.Rd 0000644 0001762 0000144 00000006270 14175213516 013426 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call2}
\alias{call2}
\title{Create a call}
\usage{
call2(.fn, ..., .ns = NULL)
}
\arguments{
\item{.fn}{Function to call. Must be a callable object: a string,
symbol, call, or a function.}
\item{...}{<\link[=dyn-dots]{dynamic}> Arguments for the function
call. Empty arguments are preserved.}
\item{.ns}{Namespace with which to prefix \code{.fn}. Must be a string
or symbol.}
}
\description{
Quoted function calls are one of the two types of
\link[=is_symbolic]{symbolic} objects in R. They represent the action of
calling a function, possibly with arguments. There are two ways of
creating a quoted call:
\itemize{
\item By \link[=nse-defuse]{quoting} it. Quoting prevents functions from being
called. Instead, you get the description of the function call as
an R object. That is, a quoted function call.
\item By constructing it with \code{\link[base:call]{base::call()}}, \code{\link[base:call]{base::as.call()}}, or
\code{call2()}. In this case, you pass the call elements (the function
to call and the arguments to call it with) separately.
}
See section below for the difference between \code{call2()} and the base
constructors.
}
\section{Difference with base constructors}{
\code{call2()} is more flexible than \code{base::call()}:
\itemize{
\item The function to call can be a string or a \link[=is_callable]{callable}
object: a symbol, another call (e.g. a \code{$} or \code{[[} call), or a
function to inline. \code{base::call()} only supports strings and you
need to use \code{base::as.call()} to construct a call with a callable
object.\preformatted{call2(list, 1, 2)
as.call(list(list, 1, 2))
}
\item The \code{.ns} argument is convenient for creating namespaced calls.\preformatted{call2("list", 1, 2, .ns = "base")
# Equivalent to
ns_call <- call("::", as.symbol("list"), as.symbol("base"))
as.call(list(ns_call, 1, 2))
}
\item \code{call2()} has \link[=list2]{dynamic dots} support. You can splice lists
of arguments with \verb{!!!} or unquote an argument name with glue
syntax.\preformatted{args <- list(na.rm = TRUE, trim = 0)
call2("mean", 1:10, !!!args)
# Equivalent to
as.call(c(list(as.symbol("mean"), 1:10), args))
}
}
}
\section{Caveats of inlining objects in calls}{
\code{call2()} makes it possible to inline objects in calls, both in
function and argument positions. Inlining an object or a function
has the advantage that the correct object is used in all
environments. If all components of the code are inlined, you can
even evaluate in the \link[=empty_env]{empty environment}.
However inlining also has drawbacks. It can cause issues with NSE
functions that expect symbolic arguments. The objects may also leak
in representations of the call stack, such as \code{\link[=traceback]{traceback()}}.
}
\examples{
# fn can either be a string, a symbol or a call
call2("f", a = 1)
call2(quote(f), a = 1)
call2(quote(f()), a = 1)
#' Can supply arguments individually or in a list
call2(quote(f), a = 1, b = 2)
call2(quote(f), !!!list(a = 1, b = 2))
# Creating namespaced calls is easy:
call2("fun", arg = quote(baz), .ns = "mypkg")
# Empty arguments are preserved:
call2("[", quote(x), , drop = )
}
\seealso{
call_modify
}
rlang/man/env.Rd 0000644 0001762 0000144 00000012337 14175213516 013222 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env.R
\name{env}
\alias{env}
\alias{child_env}
\alias{new_environment}
\title{Create a new environment}
\usage{
env(...)
child_env(.parent, ...)
new_environment(data = list(), parent = empty_env())
}
\arguments{
\item{..., data}{<\link[=dyn-dots]{dynamic}> Named values. You can
supply one unnamed to specify a custom parent, otherwise it
defaults to the current environment.}
\item{.parent, parent}{A parent environment.}
}
\description{
These functions create new environments.
\itemize{
\item \code{env()} creates a child of the current environment by default
and takes a variable number of named objects to populate it.
\item \code{new_environment()} creates a child of the empty environment by
default and takes a named list of objects to populate it.
}
}
\section{Environments as objects}{
Environments are containers of uniquely named objects. Their most
common use is to provide a scope for the evaluation of R
expressions. Not all languages have first class environments,
i.e. can manipulate scope as regular objects. Reification of scope
is one of the most powerful features of R as it allows you to change
what objects a function or expression sees when it is evaluated.
Environments also constitute a data structure in their own
right. They are a collection of uniquely named objects, subsettable
by name and modifiable by reference. This latter property (see
section on reference semantics) is especially useful for creating
mutable OO systems (cf the \href{https://github.com/r-lib/R6}{R6 package}
and the \href{https://ggplot2.tidyverse.org/articles/extending-ggplot2.html}{ggproto system}
for extending ggplot2).
}
\section{Inheritance}{
All R environments (except the \link[=empty_env]{empty environment}) are
defined with a parent environment. An environment and its
grandparents thus form a linear hierarchy that is the basis for
\href{https://en.wikipedia.org/wiki/Scope_(computer_science)}{lexical scoping} in
R. When R evaluates an expression, it looks up symbols in a given
environment. If it cannot find these symbols there, it keeps
looking them up in parent environments. This way, objects defined
in child environments have precedence over objects defined in
parent environments.
The ability of overriding specific definitions is used in the
tidyeval framework to create powerful domain-specific grammars. A
common use of masking is to put data frame columns in scope. See
for example \code{\link[=as_data_mask]{as_data_mask()}}.
}
\section{Reference semantics}{
Unlike regular objects such as vectors, environments are an
\link[=is_copyable]{uncopyable} object type. This means that if you
have multiple references to a given environment (by assigning the
environment to another symbol with \verb{<-} or passing the environment
as argument to a function), modifying the bindings of one of those
references changes all other references as well.
}
\section{Life cycle}{
\itemize{
\item \code{child_env()} is in the questioning stage. It is redundant now
that \code{env()} accepts parent environments.
}
}
\examples{
# env() creates a new environment which has the current environment
# as parent
env <- env(a = 1, b = "foo")
env$b
identical(env_parent(env), current_env())
# Supply one unnamed argument to override the default:
env <- env(base_env(), a = 1, b = "foo")
identical(env_parent(env), base_env())
# child_env() lets you specify a parent:
child <- child_env(env, c = "bar")
identical(env_parent(child), env)
# This child environment owns `c` but inherits `a` and `b` from `env`:
env_has(child, c("a", "b", "c", "d"))
env_has(child, c("a", "b", "c", "d"), inherit = TRUE)
# `parent` is passed to as_environment() to provide handy
# shortcuts. Pass a string to create a child of a package
# environment:
child_env("rlang")
env_parent(child_env("rlang"))
# Or `NULL` to create a child of the empty environment:
child_env(NULL)
env_parent(child_env(NULL))
# The base package environment is often a good default choice for a
# parent environment because it contains all standard base
# functions. Also note that it will never inherit from other loaded
# package environments since R keeps the base package at the tail
# of the search path:
base_child <- child_env("base")
env_has(base_child, c("lapply", "("), inherit = TRUE)
# On the other hand, a child of the empty environment doesn't even
# see a definition for `(`
empty_child <- child_env(NULL)
env_has(empty_child, c("lapply", "("), inherit = TRUE)
# Note that all other package environments inherit from base_env()
# as well:
rlang_child <- child_env("rlang")
env_has(rlang_child, "env", inherit = TRUE) # rlang function
env_has(rlang_child, "lapply", inherit = TRUE) # base function
# Both env() and child_env() support tidy dots features:
objs <- list(b = "foo", c = "bar")
env <- env(a = 1, !!! objs)
env$c
# You can also unquote names with the definition operator `:=`
var <- "a"
env <- env(!!var := "A")
env$a
# Use new_environment() to create containers with the empty
# environment as parent:
env <- new_environment()
env_parent(env)
# Like other new_ constructors, it takes an object rather than dots:
new_environment(list(a = "foo", b = "bar"))
}
\seealso{
\code{\link[=env_has]{env_has()}}, \code{\link[=env_bind]{env_bind()}}.
}
rlang/man/quosure-tools.Rd 0000644 0001762 0000144 00000007003 14175213516 015265 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/quo.R
\name{quosure-tools}
\alias{quosure-tools}
\alias{quosure}
\alias{quo_is_missing}
\alias{quo_is_symbol}
\alias{quo_is_call}
\alias{quo_is_symbolic}
\alias{quo_is_null}
\alias{quo_get_expr}
\alias{quo_get_env}
\alias{quo_set_expr}
\alias{quo_set_env}
\title{Quosure getters, setters and predicates}
\usage{
quo_is_missing(quo)
quo_is_symbol(quo, name = NULL)
quo_is_call(quo, name = NULL, n = NULL, ns = NULL)
quo_is_symbolic(quo)
quo_is_null(quo)
quo_get_expr(quo)
quo_get_env(quo)
quo_set_expr(quo, expr)
quo_set_env(quo, env)
}
\arguments{
\item{quo}{A quosure to test.}
\item{name}{The name of the symbol or function call. If \code{NULL} the
name is not tested.}
\item{n}{An optional number of arguments that the call should
match.}
\item{ns}{The namespace of the call. If \code{NULL}, the namespace
doesn't participate in the pattern-matching. If an empty string
\code{""} and \code{x} is a namespaced call, \code{is_call()} returns
\code{FALSE}. If any other string, \code{is_call()} checks that \code{x} is
namespaced within \code{ns}.
Can be a character vector of namespaces, in which case the call
has to match at least one of them, otherwise \code{is_call()} returns
\code{FALSE}.}
\item{expr}{A new expression for the quosure.}
\item{env}{A new environment for the quosure.}
}
\description{
These tools inspect and modify \link[=topic-quosure]{quosures}, a type of
\link[=topic-defuse]{defused expression} that includes a reference to the
context where it was created. A quosure is guaranteed to evaluate
in its original environment and can refer to local objects safely.
\itemize{
\item You can access the quosure components with \code{quo_get_expr()} and
\code{quo_get_env()}.
\item The \code{quo_} prefixed predicates test the expression of a quosure,
\code{quo_is_missing()}, \code{quo_is_symbol()}, etc.
}
All \code{quo_} prefixed functions expect a quosure and will fail if
supplied another type of object. Make sure the input is a quosure
with \code{\link[=is_quosure]{is_quosure()}}.
}
\section{Empty quosures and missing arguments}{
When missing arguments are captured as quosures, either through
\code{\link[=enquo]{enquo()}} or \code{\link[=quos]{quos()}}, they are returned as an empty quosure. These
quosures contain the \link[=missing_arg]{missing argument} and typically
have the \link[=empty_env]{empty environment} as enclosure.
Use \code{quo_is_missing()} to test for a missing argument defused with
\code{\link[=enquo]{enquo()}}.
}
\examples{
quo <- quo(my_quosure)
quo
# Access and set the components of a quosure:
quo_get_expr(quo)
quo_get_env(quo)
quo <- quo_set_expr(quo, quote(baz))
quo <- quo_set_env(quo, empty_env())
quo
# Test wether an object is a quosure:
is_quosure(quo)
# If it is a quosure, you can use the specialised type predicates
# to check what is inside it:
quo_is_symbol(quo)
quo_is_call(quo)
quo_is_null(quo)
# quo_is_missing() checks for a special kind of quosure, the one
# that contains the missing argument:
quo()
quo_is_missing(quo())
fn <- function(arg) enquo(arg)
fn()
quo_is_missing(fn())
}
\seealso{
\itemize{
\item \code{\link[=quo]{quo()}} for creating quosures by \link[=topic-defuse]{argument defusal}.
\item \code{\link[=new_quosure]{new_quosure()}} and \code{\link[=as_quosure]{as_quosure()}} for assembling quosures from
components.
\item \ifelse{html}{\link[=topic-quosure]{What are quosures and when are they needed?}}{\link[=topic-quosure]{What are quosures and when are they needed?}} for an overview.
}
}
rlang/man/missing_arg.Rd 0000644 0001762 0000144 00000013177 14175213516 014737 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/arg.R
\name{missing_arg}
\alias{missing_arg}
\alias{is_missing}
\alias{maybe_missing}
\title{Generate or handle a missing argument}
\usage{
missing_arg()
is_missing(x)
maybe_missing(x, default = missing_arg())
}
\arguments{
\item{x}{An object that might be the missing argument.}
\item{default}{The object to return if the input is missing,
defaults to \code{missing_arg()}.}
}
\description{
These functions help using the missing argument as a regular R
object.
\itemize{
\item \code{missing_arg()} generates a missing argument.
\item \code{is_missing()} is like \code{\link[base:missing]{base::missing()}} but also supports
testing for missing arguments contained in other objects like
lists. It is also more consistent with default arguments which
are never treated as missing (see section below).
\item \code{maybe_missing()} is useful to pass down an input that might be
missing to another function, potentially substituting by a
default value. It avoids triggering an "argument is missing" error.
}
}
\section{Other ways to reify the missing argument}{
\itemize{
\item \code{base::quote(expr = )} is the canonical way to create a missing
argument object.
\item \code{expr()} called without argument creates a missing argument.
\item \code{quo()} called without argument creates an empty quosure, i.e. a
quosure containing the missing argument object.
}
}
\section{\code{is_missing()} and default arguments}{
The base function \code{\link[=missing]{missing()}} makes a distinction between default
values supplied explicitly and default values generated through a
missing argument:\if{html}{\out{
}}\preformatted{## [1] FALSE
}
This only happens within a function. If the default value has been
generated in a calling function, it is never treated as missing:\if{html}{\out{
}}\preformatted{## [1] FALSE
}
\code{rlang::is_missing()} simplifies these rules by never treating
default arguments as missing, even in internal contexts:\if{html}{\out{
}}\preformatted{## [1] FALSE
}
This is a little less flexible because you can't specialise
behaviour based on implicitly supplied default values. However,
this makes the behaviour of \code{is_missing()} and functions using it
simpler to understand.
}
\section{Fragility of the missing argument object}{
The missing argument is an object that triggers an error if and
only if it is the result of evaluating a symbol. No error is
produced when a function call evaluates to the missing argument
object. For instance, it is possible to bind the missing argument
to a variable with an expression like \code{x[[1]] <- missing_arg()}.
Likewise, \code{x[[1]]} is safe to use as argument, e.g. \code{list(x[[1]])}
even when the result is the missing object.
However, as soon as the missing argument is passed down between
functions through a bare variable, it is likely to cause a missing
argument error:\if{html}{\out{
}}\preformatted{x <- missing_arg()
list(x)
#> Error:
#> ! argument "x" is missing, with no default
}\if{html}{\out{
}}
To work around this, \code{is_missing()} and \code{maybe_missing(x)} use a
bit of magic to determine if the input is the missing argument
without triggering a missing error.\if{html}{\out{
}}
\code{maybe_missing()} is particularly useful for prototyping
meta-programming algorithms in R. The missing argument is a likely
input when computing on the language because it is a standard
object in formals lists. While C functions are always allowed to
return the missing argument and pass it to other C functions, this
is not the case on the R side. If you're implementing your
meta-programming algorithm in R, use \code{maybe_missing()} when an
input might be the missing argument object.
}
\examples{
# The missing argument usually arises inside a function when the
# user omits an argument that does not have a default:
fn <- function(x) is_missing(x)
fn()
# Creating a missing argument can also be useful to generate calls
args <- list(1, missing_arg(), 3, missing_arg())
quo(fn(!!! args))
# Other ways to create that object include:
quote(expr = )
expr()
# It is perfectly valid to generate and assign the missing
# argument in a list.
x <- missing_arg()
l <- list(missing_arg())
# Just don't evaluate a symbol that contains the empty argument.
# Evaluating the object `x` that we created above would trigger an
# error.
# x # Not run
# On the other hand accessing a missing argument contained in a
# list does not trigger an error because subsetting is a function
# call:
l[[1]]
is.null(l[[1]])
# In case you really need to access a symbol that might contain the
# empty argument object, use maybe_missing():
maybe_missing(x)
is.null(maybe_missing(x))
is_missing(maybe_missing(x))
# Note that base::missing() only works on symbols and does not
# support complex expressions. For this reason the following lines
# would throw an error:
#> missing(missing_arg())
#> missing(l[[1]])
# while is_missing() will work as expected:
is_missing(missing_arg())
is_missing(l[[1]])
}
rlang/man/args_dots_empty.Rd 0000644 0001762 0000144 00000000665 14175213516 015636 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots-ellipsis.R
\name{args_dots_empty}
\alias{args_dots_empty}
\title{Helper for consistent documentation of empty dots}
\arguments{
\item{...}{These dots are for future extensions and must be empty.}
}
\description{
Use \verb{@inheritParams rlang::args_dots_empty} in your package
to consistently document \code{...} that must be empty.
}
\keyword{internal}
rlang/man/dot-data.Rd 0000644 0001762 0000144 00000004676 14175213516 014136 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval-tidy.R
\docType{data}
\name{dot-data}
\alias{dot-data}
\alias{.data}
\alias{tidyeval-data}
\alias{.env}
\title{\code{.data} and \code{.env} pronouns}
\description{
The \code{.data} and \code{.env} pronouns make it explicit where to find
objects when programming with \link[=topic-data-mask]{data-masked}
functions.\preformatted{m <- 10
mtcars \%>\% mutate(disp = .data$disp * .env$m)
}
\itemize{
\item \code{.data} retrieves data-variables from the data frame.
\item \code{.env} retrieves env-variables from the environment.
}
Because the lookup is explicit, there is no ambiguity between both
kinds of variables. Compare:\preformatted{disp <- 10
mtcars \%>\% mutate(disp = .data$disp * .env$disp)
mtcars \%>\% mutate(disp = disp * disp)
}
Note that \code{.data} is only a pronoun, it is not a real data
frame. This means that you can't take its names or map a function
over the contents of \code{.data}. Similarly, \code{.env} is not an actual R
environment. For instance, it doesn't have a parent and the
subsetting operators behave differently.
}
\section{\code{.data} versus the magrittr pronoun \code{.}}{
In a \href{https://magrittr.tidyverse.org/}{magrittr pipeline}, \code{.data}
is not necessarily interchangeable with the magrittr pronoun \code{.}.
With grouped data frames in particular, \code{.data} represents the
current group slice whereas the pronoun \code{.} represents the whole
data frame. Always prefer using \code{.data} in data-masked context.
}
\section{Where does \code{.data} live?}{
The \code{.data} pronoun is automatically created for you by
data-masking functions using the \link[=eval_tidy]{tidy eval framework}.
You don't need to import \code{rlang::.data} or use \code{library(rlang)} to
work with this pronoun.
However, the \code{.data} object exported from rlang is useful to import
in your package namespace to avoid a \verb{R CMD check} note when
referring to objects from the data mask. R does not have any way of
knowing about the presence or absence of \code{.data} in a particular
scope so you need to import it explicitly or equivalently declare
it with \code{utils::globalVariables(".data")}.
Note that \code{rlang::.data} is a "fake" pronoun. Do not refer to
\code{rlang::.data} with the \verb{rlang::} qualifier in data masking
code. Use the unqualified \code{.data} symbol that is automatically put
in scope by data-masking functions.
}
\keyword{datasets}
rlang/man/as_data_mask.Rd 0000644 0001762 0000144 00000016430 14175213516 015037 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval-tidy.R
\name{as_data_mask}
\alias{as_data_mask}
\alias{as_data_pronoun}
\alias{new_data_mask}
\title{Create a data mask}
\usage{
as_data_mask(data)
as_data_pronoun(data)
new_data_mask(bottom, top = bottom)
}
\arguments{
\item{data}{A data frame or named vector of masking data.}
\item{bottom}{The environment containing masking objects if the
data mask is one environment deep. The bottom environment if the
data mask comprises multiple environment.
If you haven't supplied \code{top}, this \strong{must} be an environment
that you own, i.e. that you have created yourself.}
\item{top}{The last environment of the data mask. If the data mask
is only one environment deep, \code{top} should be the same as
\code{bottom}.
This \strong{must} be an environment that you own, i.e. that you have
created yourself. The parent of \code{top} will be changed by the tidy
eval engine and should be considered undetermined. Never make
assumption about the parent of \code{top}.}
}
\value{
A data mask that you can supply to \code{\link[=eval_tidy]{eval_tidy()}}.
}
\description{
A \link[=topic-data-mask]{data mask} is an environment (or possibly
multiple environments forming an ancestry) containing user-supplied
objects. Objects in the mask have precedence over objects in the
environment (i.e. they mask those objects). Many R functions
evaluate quoted expressions in a data mask so these expressions can
refer to objects within the user data.
These functions let you construct a tidy eval data mask manually.
They are meant for developers of tidy eval interfaces rather than
for end users.
}
\section{Why build a data mask?}{
Most of the time you can just call \code{\link[=eval_tidy]{eval_tidy()}} with a list or a
data frame and the data mask will be constructed automatically.
There are three main use cases for manual creation of data masks:
\itemize{
\item When \code{\link[=eval_tidy]{eval_tidy()}} is called with the same data in a tight loop.
Because there is some overhead to creating tidy eval data masks,
constructing the mask once and reusing it for subsequent
evaluations may improve performance.
\item When several expressions should be evaluated in the exact same
environment because a quoted expression might create new objects
that can be referred in other quoted expressions evaluated at a
later time. One example of this is \code{tibble::lst()} where new
columns can refer to previous ones.
\item When your data mask requires special features. For instance the
data frame columns in dplyr data masks are implemented with
\link[base:delayedAssign]{active bindings}.
}
}
\section{Building your own data mask}{
Unlike \code{\link[base:eval]{base::eval()}} which takes any kind of environments as data
mask, \code{\link[=eval_tidy]{eval_tidy()}} has specific requirements in order to support
\link[=nse-defuse]{quosures}. For this reason you can't supply bare
environments.
There are two ways of constructing an rlang data mask manually:
\itemize{
\item \code{as_data_mask()} transforms a list or data frame to a data mask.
It automatically installs the data pronoun \code{\link{.data}}.
\item \code{new_data_mask()} is a bare bones data mask constructor for
environments. You can supply a bottom and a top environment in
case your data mask comprises multiple environments (see section
below).
Unlike \code{as_data_mask()} it does not install the \code{.data} pronoun
so you need to provide one yourself. You can provide a pronoun
constructed with \code{as_data_pronoun()} or your own pronoun class.
\code{as_data_pronoun()} will create a pronoun from a list, an
environment, or an rlang data mask. In the latter case, the whole
ancestry is looked up from the bottom to the top of the mask.
Functions stored in the mask are bypassed by the pronoun.
}
Once you have built a data mask, simply pass it to \code{\link[=eval_tidy]{eval_tidy()}} as
the \code{data} argument. You can repeat this as many times as
needed. Note that any objects created there (perhaps because of a
call to \verb{<-}) will persist in subsequent evaluations.
}
\section{Top and bottom of data mask}{
In some cases you'll need several levels in your data mask. One
good reason is when you include functions in the mask. It's a good
idea to keep data objects one level lower than function objects, so
that the former cannot override the definitions of the latter (see
examples).
In that case, set up all your environments and keep track of the
bottom child and the top parent. You'll need to pass both to
\code{new_data_mask()}.
Note that the parent of the top environment is completely
undetermined, you shouldn't expect it to remain the same at all
times. This parent is replaced during evaluation by \code{\link[=eval_tidy]{eval_tidy()}}
to one of the following environments:
\itemize{
\item The default environment passed as the \code{env} argument of \code{eval_tidy()}.
\item The environment of the current quosure being evaluated, if applicable.
}
Consequently, all masking data should be contained between the
bottom and top environment of the data mask.
}
\examples{
# Evaluating in a tidy evaluation environment enables all tidy
# features:
mask <- as_data_mask(mtcars)
eval_tidy(quo(letters), mask)
# You can install new pronouns in the mask:
mask$.pronoun <- as_data_pronoun(list(foo = "bar", baz = "bam"))
eval_tidy(quo(.pronoun$foo), mask)
# In some cases the data mask can leak to the user, for example if
# a function or formula is created in the data mask environment:
cyl <- "user variable from the context"
fn <- eval_tidy(quote(function() cyl), mask)
fn()
# If new objects are created in the mask, they persist in the
# subsequent calls:
eval_tidy(quote(new <- cyl + am), mask)
eval_tidy(quote(new * 2), mask)
# In some cases your data mask is a whole chain of environments
# rather than a single environment. You'll have to use
# `new_data_mask()` and let it know about the bottom of the mask
# (the last child of the environment chain) and the topmost parent.
# A common situation where you'll want a multiple-environment mask
# is when you include functions in your mask. In that case you'll
# put functions in the top environment and data in the bottom. This
# will prevent the data from overwriting the functions.
top <- new_environment(list(`+` = base::paste, c = base::paste))
# Let's add a middle environment just for sport:
middle <- env(top)
# And finally the bottom environment containing data:
bottom <- env(middle, a = "a", b = "b", c = "c")
# We can now create a mask by supplying the top and bottom
# environments:
mask <- new_data_mask(bottom, top = top)
# This data mask can be passed to eval_tidy() instead of a list or
# data frame:
eval_tidy(quote(a + b + c), data = mask)
# Note how the function `c()` and the object `c` are looked up
# properly because of the multi-level structure:
eval_tidy(quote(c(a, b, c)), data = mask)
# new_data_mask() does not create data pronouns, but
# data pronouns can be added manually:
mask$.fns <- as_data_pronoun(top)
# The `.data` pronoun should generally be created from the
# mask. This will ensure data is looked up throughout the whole
# ancestry. Only non-function objects are looked up from this
# pronoun:
mask$.data <- as_data_pronoun(mask)
mask$.data$c
# Now we can reference values with the pronouns:
eval_tidy(quote(c(.data$a, .data$b, .data$c)), data = mask)
}
rlang/man/op-null-default.Rd 0000644 0001762 0000144 00000001000 13563526752 015434 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/operators.R
\name{op-null-default}
\alias{op-null-default}
\alias{\%||\%}
\title{Default value for \code{NULL}}
\usage{
x \%||\% y
}
\arguments{
\item{x, y}{If \code{x} is NULL, will return \code{y}; otherwise returns \code{x}.}
}
\description{
This infix function makes it easy to replace \code{NULL}s with a default
value. It's inspired by the way that Ruby's or operation (\code{||})
works.
}
\examples{
1 \%||\% 2
NULL \%||\% 2
}
rlang/man/fn_fmls.Rd 0000644 0001762 0000144 00000002517 14175213516 014055 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{fn_fmls}
\alias{fn_fmls}
\alias{fn_fmls_names}
\alias{fn_fmls_syms}
\alias{fn_fmls<-}
\alias{fn_fmls_names<-}
\title{Extract arguments from a function}
\usage{
fn_fmls(fn = caller_fn())
fn_fmls_names(fn = caller_fn())
fn_fmls_syms(fn = caller_fn())
fn_fmls(fn) <- value
fn_fmls_names(fn) <- value
}
\arguments{
\item{fn}{A function. It is looked up in the calling frame if not
supplied.}
\item{value}{New formals or formals names for \code{fn}.}
}
\description{
\code{fn_fmls()} returns a named list of formal arguments.
\code{fn_fmls_names()} returns the names of the arguments.
\code{fn_fmls_syms()} returns formals as a named list of symbols. This
is especially useful for forwarding arguments in \link[=lang]{constructed calls}.
}
\details{
Unlike \code{formals()}, these helpers throw an error with primitive
functions instead of returning \code{NULL}.
}
\examples{
# Extract from current call:
fn <- function(a = 1, b = 2) fn_fmls()
fn()
# fn_fmls_syms() makes it easy to forward arguments:
call2("apply", !!! fn_fmls_syms(lapply))
# You can also change the formals:
fn_fmls(fn) <- list(A = 10, B = 20)
fn()
fn_fmls_names(fn) <- c("foo", "bar")
fn()
}
\seealso{
\code{\link[=call_args]{call_args()}} and \code{\link[=call_args_names]{call_args_names()}}
}
rlang/man/chr_unserialise_unicode.Rd 0000644 0001762 0000144 00000003012 14175213516 017305 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-encoding.R
\name{chr_unserialise_unicode}
\alias{chr_unserialise_unicode}
\title{Translate unicode points to UTF-8}
\usage{
chr_unserialise_unicode(chr)
}
\arguments{
\item{chr}{A character vector.}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
For historical reasons, R translates strings to the native encoding
when they are converted to symbols. This string-to-symbol
conversion is not a rare occurrence and happens for instance to the
names of a list of arguments converted to a call by \code{do.call()}.
If the string contains unicode characters that cannot be
represented in the native encoding, R serialises those as an ASCII
sequence representing the unicode point. This is why Windows users
with western locales often see strings looking like \verb{}. To
alleviate some of the pain, rlang parses strings and looks for
serialised unicode points to translate them back to the proper
UTF-8 representation. This transformation occurs automatically in
functions like \code{\link[=env_names]{env_names()}} and can be manually triggered with
\code{as_utf8_character()} and \code{chr_unserialise_unicode()}.
}
\section{Life cycle}{
This function is experimental.
}
\examples{
ascii <- ""
chr_unserialise_unicode(ascii)
identical(chr_unserialise_unicode(ascii), "\u5e78")
}
\keyword{internal}
rlang/man/env_unbind.Rd 0000644 0001762 0000144 00000002276 14127057575 014572 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-binding.R
\name{env_unbind}
\alias{env_unbind}
\title{Remove bindings from an environment}
\usage{
env_unbind(env = caller_env(), nms, inherit = FALSE)
}
\arguments{
\item{env}{An environment.}
\item{nms}{A character vector of binding names to remove.}
\item{inherit}{Whether to look for bindings in the parent
environments.}
}
\value{
The input object \code{env} with its associated environment
modified in place, invisibly.
}
\description{
\code{env_unbind()} is the complement of \code{\link[=env_bind]{env_bind()}}. Like \code{env_has()},
it ignores the parent environments of \code{env} by default. Set
\code{inherit} to \code{TRUE} to track down bindings in parent environments.
}
\examples{
env <- env(foo = 1, bar = 2)
env_has(env, c("foo", "bar"))
# Remove bindings with `env_unbind()`
env_unbind(env, c("foo", "bar"))
env_has(env, c("foo", "bar"))
# With inherit = TRUE, it removes bindings in parent environments
# as well:
parent <- env(empty_env(), foo = 1, bar = 2)
env <- env(parent, foo = "b")
env_unbind(env, "foo", inherit = TRUE)
env_has(env, c("foo", "bar"))
env_has(env, c("foo", "bar"), inherit = TRUE)
}
rlang/man/is_expression.Rd 0000644 0001762 0000144 00000007157 14175213516 015330 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/expr.R
\name{is_expression}
\alias{is_expression}
\alias{is_syntactic_literal}
\alias{is_symbolic}
\title{Is an object an expression?}
\usage{
is_expression(x)
is_syntactic_literal(x)
is_symbolic(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
In rlang, an \emph{expression} is the return type of \code{\link[=parse_expr]{parse_expr()}}, the
set of objects that can be obtained from parsing R code. Under this
definition expressions include numbers, strings, \code{NULL}, symbols,
and function calls. These objects can be classified as:
\itemize{
\item Symbolic objects, i.e. symbols and function calls (for which
\code{is_symbolic()} returns \code{TRUE})
\item Syntactic literals, i.e. scalar atomic objects and \code{NULL}
(testable with \code{is_syntactic_literal()})
}
\code{is_expression()} returns \code{TRUE} if the input is either a symbolic
object or a syntactic literal. If a call, the elements of the call
must all be expressions as well. Unparsable calls are not
considered expressions in this narrow definition.
Note that in base R, there exists \code{\link[=expression]{expression()}} vectors, a data
type similar to a list that supports special attributes created by
the parser called source references. This data type is not
supported in rlang.
}
\details{
\code{is_symbolic()} returns \code{TRUE} for symbols and calls (objects with
type \code{language}). Symbolic objects are replaced by their value
during evaluation. Literals are the complement of symbolic
objects. They are their own value and return themselves during
evaluation.
\code{is_syntactic_literal()} is a predicate that returns \code{TRUE} for the
subset of literals that are created by R when parsing text (see
\code{\link[=parse_expr]{parse_expr()}}): numbers, strings and \code{NULL}. Along with symbols,
these literals are the terminating nodes in an AST.
Note that in the most general sense, a literal is any R object that
evaluates to itself and that can be evaluated in the empty
environment. For instance, \code{quote(c(1, 2))} is not a literal, it is
a call. However, the result of evaluating it in \code{\link[=base_env]{base_env()}} is a
literal(in this case an atomic vector).
As the data structure for function arguments, pairlists are also a
kind of language objects. However, since they are mostly an
internal data structure and can't be returned as is by the parser,
\code{is_expression()} returns \code{FALSE} for pairlists.
}
\examples{
q1 <- quote(1)
is_expression(q1)
is_syntactic_literal(q1)
q2 <- quote(x)
is_expression(q2)
is_symbol(q2)
q3 <- quote(x + 1)
is_expression(q3)
is_call(q3)
# Atomic expressions are the terminating nodes of a call tree:
# NULL or a scalar atomic vector:
is_syntactic_literal("string")
is_syntactic_literal(NULL)
is_syntactic_literal(letters)
is_syntactic_literal(quote(call()))
# Parsable literals have the property of being self-quoting:
identical("foo", quote("foo"))
identical(1L, quote(1L))
identical(NULL, quote(NULL))
# Like any literals, they can be evaluated within the empty
# environment:
eval_bare(quote(1L), empty_env())
# Whereas it would fail for symbolic expressions:
# eval_bare(quote(c(1L, 2L)), empty_env())
# Pairlists are also language objects representing argument lists.
# You will usually encounter them with extracted formals:
fmls <- formals(is_expression)
typeof(fmls)
# Since they are mostly an internal data structure, is_expression()
# returns FALSE for pairlists, so you will have to check explicitly
# for them:
is_expression(fmls)
is_pairlist(fmls)
}
\seealso{
\code{\link[=is_call]{is_call()}} for a call predicate.
}
rlang/man/check_dots_unnamed.Rd 0000644 0001762 0000144 00000002422 14175213516 016241 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots-ellipsis.R
\name{check_dots_unnamed}
\alias{check_dots_unnamed}
\title{Check that all dots are unnamed}
\usage{
check_dots_unnamed(
env = caller_env(),
error = NULL,
call = caller_env(),
action = abort
)
}
\arguments{
\item{env}{Environment in which to look for \code{...}.}
\item{error}{An optional error handler passed to \code{\link[=try_fetch]{try_fetch()}}. Use
this e.g. to demote an error into a warning.}
\item{call}{The execution environment of a currently
running function, e.g. \code{caller_env()}. The function will be
mentioned in error messages as the source of the error. See the
\code{call} argument of \code{\link[=abort]{abort()}} for more information.}
\item{action}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}}
}
\description{
In functions like \code{paste()}, named arguments in \code{...} are often a
sign of misspelled argument names. Call \code{check_dots_unnamed()} to
fail with an error when named arguments are detected.
}
\examples{
f <- function(..., foofy = 8) {
check_dots_unnamed()
c(...)
}
f(1, 2, 3, foofy = 4)
try(f(1, 2, 3, foof = 4))
}
rlang/man/is_call.Rd 0000644 0001762 0000144 00000005102 14175213516 014030 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{is_call}
\alias{is_call}
\title{Is object a call?}
\usage{
is_call(x, name = NULL, n = NULL, ns = NULL)
}
\arguments{
\item{x}{An object to test. Formulas and quosures are treated
literally.}
\item{name}{An optional name that the call should match. It is
passed to \code{\link[=sym]{sym()}} before matching. This argument is vectorised
and you can supply a vector of names to match. In this case,
\code{is_call()} returns \code{TRUE} if at least one name matches.}
\item{n}{An optional number of arguments that the call should
match.}
\item{ns}{The namespace of the call. If \code{NULL}, the namespace
doesn't participate in the pattern-matching. If an empty string
\code{""} and \code{x} is a namespaced call, \code{is_call()} returns
\code{FALSE}. If any other string, \code{is_call()} checks that \code{x} is
namespaced within \code{ns}.
Can be a character vector of namespaces, in which case the call
has to match at least one of them, otherwise \code{is_call()} returns
\code{FALSE}.}
}
\description{
This function tests if \code{x} is a \link[=call2]{call}. This is a
pattern-matching predicate that returns \code{FALSE} if \code{name} and \code{n}
are supplied and the call does not match these properties.
}
\examples{
is_call(quote(foo(bar)))
# You can pattern-match the call with additional arguments:
is_call(quote(foo(bar)), "foo")
is_call(quote(foo(bar)), "bar")
is_call(quote(foo(bar)), quote(foo))
# Match the number of arguments with is_call():
is_call(quote(foo(bar)), "foo", 1)
is_call(quote(foo(bar)), "foo", 2)
# By default, namespaced calls are tested unqualified:
ns_expr <- quote(base::list())
is_call(ns_expr, "list")
# You can also specify whether the call shouldn't be namespaced by
# supplying an empty string:
is_call(ns_expr, "list", ns = "")
# Or if it should have a namespace:
is_call(ns_expr, "list", ns = "utils")
is_call(ns_expr, "list", ns = "base")
# You can supply multiple namespaces:
is_call(ns_expr, "list", ns = c("utils", "base"))
is_call(ns_expr, "list", ns = c("utils", "stats"))
# If one of them is "", unnamespaced calls will match as well:
is_call(quote(list()), "list", ns = "base")
is_call(quote(list()), "list", ns = c("base", ""))
is_call(quote(base::list()), "list", ns = c("base", ""))
# The name argument is vectorised so you can supply a list of names
# to match with:
is_call(quote(foo(bar)), c("bar", "baz"))
is_call(quote(foo(bar)), c("bar", "foo"))
is_call(quote(base::list), c("::", ":::", "$", "@"))
}
\seealso{
\code{\link[=is_expression]{is_expression()}}
}
rlang/man/friendly_type.Rd 0000644 0001762 0000144 00000001250 14175213516 015277 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-deprecated.R
\name{friendly_type}
\alias{friendly_type}
\title{Format a type for error messages}
\usage{
friendly_type(type)
}
\arguments{
\item{type}{A type as returned by \code{\link[=typeof]{typeof()}}.}
}
\value{
A string of the prettified type, qualified with an
indefinite article.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}
\code{friendly_type()} is deprecated. Please use the
\code{compat-friendly-type.R} file instead.
}
\keyword{internal}
rlang/man/notes/ 0000755 0001762 0000144 00000000000 14175213516 013265 5 ustar ligges users rlang/man/notes/handling-introspection.R 0000644 0001762 0000144 00000017644 14175213516 020106 0 ustar ligges users # This file surveys the possible backtraces created during condition
# handling. We are interested in detecting the following frames:
#
# - Setup frame, e.g. `withCallingHandlers()` or `tryCatch()`. The
# caller of this frame is useful as the default `call` when
# rethrowing an error.
#
# - Signal frame, e.g. `stop()`, `warning()`, `signalCondition()`. Can
# be a user frame as well when the condition is signalled from C,
# e.g. with `Rf_error()`.
#
# - Handler frame. This is adjascent to the signal frame but may have
# various intervening frames in between. Mostly this is about
# detecting that we rethrowing from a handler.
#
# Knowing about these frames is useful for backtrace simplification
# (the default display in `rlang::last_error()`) and for figuring out
# a good default `call` field.
#
#
# # Backtrace simplification
#
# We generally want to hide everything between the signal frame and
# the handler frame. It's particularly important for the linear
# display of backtraces where we subset the last branch of the
# backtrace tree. If we didn't clean these frames, the user context
# would disappear in favour of (or in the best case be drowned in)
# condition handling frames.
#
#
# # Default call inference
#
# When rethrowing a chained error, the relevant `call` field is the
# caller of `withCallingHandlers()`. The backtrace between that setup
# frame and the signal frame can be arbitrarily large and there is
# currently no way of finding the setup frame with 100% reliability
# (there might be several on the stack).
f <- function() {
throw()
}
handle <- function(...) {
handler_helper()
invokeRestart("abort")
}
handler_helper <- function() {
print(rlang::trace_back())
}
# Errors - Calling handlers
foo <- function(...) {
withCallingHandlers(f(), ...)
}
### Text error
# Setup: 2
# Signal: 5
# Handler: 7
throw <- function() stop("foo")
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::stop("foo")
#> 6. └─base::.handleSimpleError(``, "foo", base::quote(throw()))
#> >7. └─global h(simpleError(msg, call))
#> 8. └─global handler_helper()
### Condition error
# Setup: 2
# Signal: 5
# Handler: 6
throw <- function() stop(simpleError("foo"))
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::stop(simpleError("foo"))
#> >6. └─global ``(``)
#> 7. └─global handler_helper()
### Condition error, simple signal
# Setup: 2
# Signal: 5
# Handler: 6
throw <- function() signalCondition(simpleError("foo"))
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::signalCondition(simpleError("foo"))
#> >6. └─global ``(``)
#> 7. └─global handler_helper()
### Condition error, demoted to warning
# Setup: 2
# Signal: 5
# Handler: 9
throw <- function() warning(simpleError("foo"))
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::warning(simpleError("foo"))
#> 6. │ └─base::withRestarts(...)
#> 7. │ └─base withOneRestart(expr, restarts[[1L]])
#> 8. │ └─base doWithOneRestart(return(expr), restart)
#> >9. └─global ``(``)
#> 10. └─global handler_helper()
### Condition error, demoted to message
# Setup: 2
# Signal: 5
# Handler: 10
throw <- function() message(simpleError("foo"))
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> 2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> 5. │ └─base::message(simpleError("foo"))
#> 6. │ ├─base::withRestarts(...)
#> 7. │ │ └─base withOneRestart(expr, restarts[[1L]])
#> 8. │ │ └─base doWithOneRestart(return(expr), restart)
#> 9. │ └─base::signalCondition(cond)
#> 10. └─global ``(``)
#> 11. └─global handler_helper()
### C-level error
# In this case, the signal frame is a user function.
# Setup: 2
# Signal: 5
# Handler: 7
throw <- function() rlang:::errorcall(NULL, "foo")
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─rlang:::errorcall(NULL, "foo")
#> 6. └─base::.handleSimpleError(``, "foo", base::quote(NULL))
#> >7. └─global h(simpleError(msg, call))
#> 8. └─global handler_helper()
### Text warning promoted to error
# The stack is not linear between 5 and 11. Compare to the next
# backtrace which is linear(ish).
# Setup: 2
# Signal: 5
# Handler: 11
throw <- function() {
rlang::local_options(warn = 2)
warning("foo")
}
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::warning("foo")
#> 6. ├─base::.signalSimpleWarning("foo", base::quote(throw()))
#> 7. │ └─base::withRestarts(...)
#> 8. │ └─base withOneRestart(expr, restarts[[1L]])
#> 9. │ └─base doWithOneRestart(return(expr), restart)
#> 10. └─base::.handleSimpleError(...)
#> >11. └─global h(simpleError(msg, call))
#> 12. └─global handler_helper()
### Condition warning promoted to error
# Setup: 2
# Signal: 5
# Handler: 10
throw <- function() {
rlang::local_options(warn = 2)
warning(simpleWarning("foo"))
}
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> >2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> >5. │ └─base::warning(simpleWarning("foo"))
#> 6. │ └─base::withRestarts(...)
#> 7. │ └─base withOneRestart(expr, restarts[[1L]])
#> 8. │ └─base doWithOneRestart(return(expr), restart)
#> 9. └─base::.handleSimpleError(...)
#> >10. └─global h(simpleError(msg, call))
#> 11. └─global handler_helper()
### rlang error
# Setup: 2
# Signal: 5
# Handler: 10
throw <- function() rlang::abort("foo")
foo(error = handle)
#> â–†
#> 1. ├─global foo(error = handle)
#> 2. │ ├─base::withCallingHandlers(f(), ...)
#> 3. │ └─global f()
#> 4. │ └─global throw()
#> 5. │ └─rlang::abort("foo")
#> 6. │ └─rlang::signal_abort(cnd, .file) at rlang/R/cnd-abort.R:281:2
#> 7. │ └─base::signalCondition(cnd) at rlang/R/cnd-abort.R:641:4
#> 8. └─global ``(``)
#> 9. └─global handler_helper()
# Errors - Exiting handlers
# This is much easier, all the stacks look the same!
bar <- function(...) {
tryCatch(f(), ...)
}
# These all produce the same stack
throw <- function() stop("foo")
throw <- function() stop(simpleError("foo"))
throw <- function() rlang:::errorcall(NULL, "foo")
throw <- function() {
rlang::local_options(warn = 2)
warning("foo")
}
# Setup: 2
# Handler: 5
bar(error = handle)
#> â–†
#> 1. └─global bar(error = handle)
#> >2. └─base::tryCatch(f(), ...)
#> 3. └─base tryCatchList(expr, classes, parentenv, handlers)
#> 4. └─base tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> >5. └─value[[3L]](cond)
#> 6. └─global handler_helper()
# The stack could be larger between 2 and 5 depending on the number of
# condition handlers passed to `tryCatch()`.
rlang/man/names_inform_repair.Rd 0000644 0001762 0000144 00000002045 14175213516 016444 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/names.R
\name{names_inform_repair}
\alias{names_inform_repair}
\title{Inform about name repair}
\usage{
names_inform_repair(old, new)
}
\arguments{
\item{old}{Original names vector.}
\item{new}{Repaired names vector.}
}
\description{
Inform about name repair
}
\section{Muffling and silencing messages}{
Name repair messages are signaled with \code{\link[=inform]{inform()}} and are given the class
\code{"rlib_message_name_repair"}. These messages can be muffled with
\code{\link[base:message]{base::suppressMessages()}}.
Name repair messages can also be silenced with the global option
\code{rlib_name_repair_verbosity}. This option takes the values:
\itemize{
\item \code{"verbose"}: Always verbose.
\item \code{"quiet"}: Always quiet.
}
When set to quiet, the message is not displayed and the condition is not
signaled. This is particularly useful for silencing messages during testing
when combined with \code{\link[=local_options]{local_options()}}.
}
\keyword{internal}
rlang/man/set_names.Rd 0000644 0001762 0000144 00000003255 14175213516 014407 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/attr.R
\name{set_names}
\alias{set_names}
\title{Set names of a vector}
\usage{
set_names(x, nm = x, ...)
}
\arguments{
\item{x}{Vector to name.}
\item{nm, ...}{Vector of names, the same length as \code{x}. If length 1,
\code{nm} is recycled to the length of \code{x} following the recycling
rules of the tidyverse..
You can specify names in the following ways:
\itemize{
\item If not supplied, \code{x} will be named to \code{as.character(x)}.
\item If \code{x} already has names, you can provide a function or formula
to transform the existing names. In that case, \code{...} is passed
to the function.
\item Otherwise if \code{...} is supplied, \code{x} is named to \code{c(nm, ...)}.
\item If \code{nm} is \code{NULL}, the names are removed (if present).
}}
}
\description{
This is equivalent to \code{\link[stats:setNames]{stats::setNames()}}, with more features and
stricter argument checking.
}
\section{Life cycle}{
\code{set_names()} is stable and exported in purrr.
}
\examples{
set_names(1:4, c("a", "b", "c", "d"))
set_names(1:4, letters[1:4])
set_names(1:4, "a", "b", "c", "d")
# If the second argument is ommitted a vector is named with itself
set_names(letters[1:5])
# Alternatively you can supply a function
set_names(1:10, ~ letters[seq_along(.)])
set_names(head(mtcars), toupper)
# If the input vector is unnamed, it is first named after itself
# before the function is applied:
set_names(letters, toupper)
# `...` is passed to the function:
set_names(head(mtcars), paste0, "_foo")
# If length 1, the second argument is recycled to the length of the first:
set_names(1:3, "foo")
set_names(list(), "")
}
rlang/man/is_function.Rd 0000644 0001762 0000144 00000007705 14175213516 014755 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{is_function}
\alias{is_function}
\alias{is_closure}
\alias{is_primitive}
\alias{is_primitive_eager}
\alias{is_primitive_lazy}
\title{Is object a function?}
\usage{
is_function(x)
is_closure(x)
is_primitive(x)
is_primitive_eager(x)
is_primitive_lazy(x)
}
\arguments{
\item{x}{Object to be tested.}
}
\description{
The R language defines two different types of functions: primitive
functions, which are low-level, and closures, which are the regular
kind of functions.
}
\details{
Closures are functions written in R, named after the way their
arguments are scoped within nested environments (see
\url{https://en.wikipedia.org/wiki/Closure_(computer_programming)}). The
root environment of the closure is called the closure
environment. When closures are evaluated, a new environment called
the evaluation frame is created with the closure environment as
parent. This is where the body of the closure is evaluated. These
closure frames appear on the evaluation stack, as opposed to
primitive functions which do not necessarily have their own
evaluation frame and never appear on the stack.
Primitive functions are more efficient than closures for two
reasons. First, they are written entirely in fast low-level
code. Second, the mechanism by which they are passed arguments is
more efficient because they often do not need the full procedure of
argument matching (dealing with positional versus named arguments,
partial matching, etc). One practical consequence of the special
way in which primitives are passed arguments is that they
technically do not have formal arguments, and \code{\link[=formals]{formals()}} will
return \code{NULL} if called on a primitive function. Finally, primitive
functions can either take arguments lazily, like R closures do,
or evaluate them eagerly before being passed on to the C code.
The former kind of primitives are called "special" in R terminology,
while the latter is referred to as "builtin". \code{is_primitive_eager()}
and \code{is_primitive_lazy()} allow you to check whether a primitive
function evaluates arguments eagerly or lazily.
You will also encounter the distinction between primitive and
internal functions in technical documentation. Like primitive
functions, internal functions are defined at a low level and
written in C. However, internal functions have no representation in
the R language. Instead, they are called via a call to
\code{\link[base:Internal]{base::.Internal()}} within a regular closure. This ensures that
they appear as normal R function objects: they obey all the usual
rules of argument passing, and they appear on the evaluation stack
as any other closures. As a result, \code{\link[=fn_fmls]{fn_fmls()}} does not need to
look in the \code{.ArgsEnv} environment to obtain a representation of
their arguments, and there is no way of querying from R whether
they are lazy ('special' in R terminology) or eager ('builtin').
You can call primitive functions with \code{\link[=.Primitive]{.Primitive()}} and internal
functions with \code{\link[=.Internal]{.Internal()}}. However, calling internal functions
in a package is forbidden by CRAN's policy because they are
considered part of the private API. They often assume that they
have been called with correctly formed arguments, and may cause R
to crash if you call them with unexpected objects.
}
\examples{
# Primitive functions are not closures:
is_closure(base::c)
is_primitive(base::c)
# On the other hand, internal functions are wrapped in a closure
# and appear as such from the R side:
is_closure(base::eval)
# Both closures and primitives are functions:
is_function(base::c)
is_function(base::eval)
# Many primitive functions evaluate arguments eagerly:
is_primitive_eager(base::c)
is_primitive_eager(base::list)
is_primitive_eager(base::`+`)
# However, primitives that operate on expressions, like quote() or
# substitute(), are lazy:
is_primitive_lazy(base::quote)
is_primitive_lazy(base::substitute)
}
rlang/man/is_pairlist.Rd 0000644 0001762 0000144 00000001710 13351410654 014742 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/node.R
\name{is_pairlist}
\alias{is_pairlist}
\alias{is_node}
\alias{is_node_list}
\title{Is object a node or pairlist?}
\usage{
is_pairlist(x)
is_node(x)
is_node_list(x)
}
\arguments{
\item{x}{Object to test.}
}
\description{
\itemize{
\item \code{is_pairlist()} checks that \code{x} has type \code{pairlist}.
\item \code{is_node()} checks that \code{x} has type \code{pairlist} or \code{language}.
It tests whether \code{x} is a node that has a CAR and a CDR,
including callable nodes (language objects).
\item \code{is_node_list()} checks that \code{x} has type \code{pairlist} or \code{NULL}.
\code{NULL} is the empty node list.
}
}
\section{Life cycle}{
These functions are experimental. We are still figuring out a good
naming convention to refer to the different lisp-like lists in R.
}
\seealso{
\code{\link[=is_call]{is_call()}} tests for language nodes.
}
\keyword{internal}
rlang/man/format_error_bullets.Rd 0000644 0001762 0000144 00000004514 14175213516 016663 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-message.R
\name{format_error_bullets}
\alias{format_error_bullets}
\title{Format bullets for error messages}
\usage{
format_error_bullets(x)
}
\arguments{
\item{x}{A named character vector of messages. Named elements are
prefixed with the corresponding bullet. Elements named with a
single space \code{" "} trigger a line break from the previous bullet.}
}
\description{
\code{format_error_bullets()} takes a character vector and returns a single
string (or an empty vector if the input is empty). The elements of
the input vector are assembled as a list of bullets, depending on
their names:
\itemize{
\item Unnamed elements are unindented. They act as titles or subtitles.
\item Elements named \code{"*"} are bulleted with a cyan "bullet" symbol.
\item Elements named \code{"i"} are bulleted with a blue "info" symbol.
\item Elements named \code{"x"} are bulleted with a red "cross" symbol.
\item Elements named \code{"v"} are bulleted with a green "tick" symbol.
\item Elements named \code{"!"} are bulleted with a yellow "warning" symbol.
\item Elements named \code{">"} are bulleted with an "arrow" symbol.
\item Elements named \code{" "} start with an indented line break.
}
For convenience, if the vector is fully unnamed, the elements are
formatted as "*" bullets.
The bullet formatting for errors follows the idea that sentences in
error messages are best kept short and simple. The best way to
present the information is in the \code{\link[=cnd_body]{cnd_body()}} method of an error
conditon as a bullet list of simple sentences containing a single
clause. The info and cross symbols of the bullets provide hints on
how to interpret the bullet relative to the general error issue,
which should be supplied as \code{\link[=cnd_header]{cnd_header()}}.
}
\examples{
# All bullets
writeLines(format_error_bullets(c("foo", "bar")))
# This is equivalent to
writeLines(format_error_bullets(set_names(c("foo", "bar"), "*")))
# Supply named elements to format info, cross, and tick bullets
writeLines(format_error_bullets(c(i = "foo", x = "bar", v = "baz", "*" = "quux")))
# An unnamed element breaks the line
writeLines(format_error_bullets(c(i = "foo\nbar")))
# A " " element breaks the line within a bullet (with indentation)
writeLines(format_error_bullets(c(i = "foo", " " = "bar")))
}
rlang/man/fn_env.Rd 0000644 0001762 0000144 00000001737 14175213516 013707 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fn.R
\name{fn_env}
\alias{fn_env}
\alias{fn_env<-}
\title{Return the closure environment of a function}
\usage{
fn_env(fn)
fn_env(x) <- value
}
\arguments{
\item{fn, x}{A function.}
\item{value}{A new closure environment for the function.}
}
\description{
Closure environments define the scope of functions (see \code{\link[=env]{env()}}).
When a function call is evaluated, R creates an evaluation frame
that inherits from the closure environment. This makes all objects
defined in the closure environment and all its parents available to
code executed within the function.
}
\details{
\code{fn_env()} returns the closure environment of \code{fn}. There is also
an assignment method to set a new closure environment.
}
\examples{
env <- child_env("base")
fn <- with_env(env, function() NULL)
identical(fn_env(fn), env)
other_env <- child_env("base")
fn_env(fn) <- other_env
identical(fn_env(fn), other_env)
}
rlang/man/global_entrace.Rd 0000644 0001762 0000144 00000003041 14175213516 015363 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-entrace.R
\name{global_entrace}
\alias{global_entrace}
\title{Entrace unexpected errors}
\usage{
global_entrace(enable = TRUE, class = c("error", "warning", "message"))
}
\arguments{
\item{enable}{Whether to enable or disable global handling.}
\item{class}{A character vector of one or several classes of
conditions to be entraced.}
}
\description{
\code{global_entrace()} enriches base errors with rlang features:
\itemize{
\item They are assigned a backtrace. You can configure whether to
display a backtrace on error with the \link{rlang_backtrace_on_error}
global option.
\item They are recorded in \code{\link[=last_error]{last_error()}}. Calling this function is
another way of inspecting the backtrace.
}
When global entracing is enabled, all errors behave as if they had
been thrown with \code{\link[=abort]{abort()}}, even the ones thrown with
\code{\link[=stop]{stop()}} or from native code.
Set global entracing in your RProfile with:\preformatted{rlang::global_entrace()
}
}
\section{Under the hood}{
On R 4.0 and newer, \code{global_entrace()} installs a global handler
with \code{globalCallingHandlers()}. On older R versions, \code{entrace()} is
set as an \code{option(error = )} handler. The latter method has the
disadvantage that only one handler can be set at a time. This means
that you need to manually switch between \code{entrace()} and other
handlers like \code{\link[=recover]{recover()}}. Also this causes a conflict with IDE
handlers (e.g. in RStudio).
}
rlang/man/local_options.Rd 0000644 0001762 0000144 00000004213 14127057575 015301 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/state.R
\name{local_options}
\alias{local_options}
\alias{with_options}
\alias{push_options}
\alias{peek_options}
\alias{peek_option}
\title{Change global options}
\usage{
local_options(..., .frame = caller_env())
with_options(.expr, ...)
push_options(...)
peek_options(...)
peek_option(name)
}
\arguments{
\item{...}{For \code{local_options()} and \code{push_options()}, named
values defining new option values. For \code{peek_options()}, strings
or character vectors of option names.}
\item{.frame}{The environment of a stack frame which defines the
scope of the temporary options. When the frame returns, the
options are set back to their original values.}
\item{.expr}{An expression to evaluate with temporary options.}
\item{name}{An option name as string.}
}
\value{
For \code{local_options()} and \code{push_options()}, the old option
values. \code{peek_option()} returns the current value of an option
while the plural \code{peek_options()} returns a list of current
option values.
}
\description{
\itemize{
\item \code{local_options()} changes options for the duration of a stack
frame (by default the current one). Options are set back to their
old values when the frame returns.
\item \code{with_options()} changes options while an expression is
evaluated. Options are restored when the expression returns.
\item \code{push_options()} adds or changes options permanently.
\item \code{peek_option()} and \code{peek_options()} return option values. The
former returns the option directly while the latter returns a
list.
}
}
\section{Life cycle}{
These functions are experimental.
}
\examples{
# Store and retrieve a global option:
push_options(my_option = 10)
peek_option("my_option")
# Change the option temporarily:
with_options(my_option = 100, peek_option("my_option"))
peek_option("my_option")
# The scoped variant is useful within functions:
fn <- function() {
local_options(my_option = 100)
peek_option("my_option")
}
fn()
peek_option("my_option")
# The plural peek returns a named list:
peek_options("my_option")
peek_options("my_option", "digits")
}
\keyword{experimental}
rlang/man/figures/ 0000755 0001762 0000144 00000000000 14175213516 013601 5 ustar ligges users rlang/man/figures/lifecycle-defunct.svg 0000644 0001762 0000144 00000001704 14127057575 017721 0 ustar ligges users