rlang/ 0000755 0001762 0000144 00000000000 13614116052 011354 5 ustar ligges users rlang/NAMESPACE 0000644 0001762 0000144 00000025067 13612354377 012621 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("[",quosure)
S3method("[",quosures)
S3method("[",rlang_data_pronoun)
S3method("[",rlang_envs)
S3method("[",stack)
S3method("[<-",quosures)
S3method("[[",quosure)
S3method("[[",rlang_ctxt_pronoun)
S3method("[[",rlang_data_pronoun)
S3method("[[",rlang_fake_data_pronoun)
S3method("[[<-",quosures)
S3method("[[<-",rlang_ctxt_pronoun)
S3method("[[<-",rlang_data_pronoun)
S3method(Math,quosure)
S3method(Ops,quosure)
S3method(Summary,quosure)
S3method(as.character,quosure)
S3method(as.list,quosures)
S3method(c,quosures)
S3method(c,rlang_envs)
S3method(cnd_body,default)
S3method(cnd_footer,default)
S3method(cnd_header,default)
S3method(conditionMessage,rlang_error)
S3method(format,rlang_error)
S3method(format,rlang_trace)
S3method(length,rlang_ctxt_pronoun)
S3method(length,rlang_data_pronoun)
S3method(length,rlang_fake_data_pronoun)
S3method(mean,quosure)
S3method(median,quosure)
S3method(names,rlang_ctxt_pronoun)
S3method(names,rlang_data_pronoun)
S3method(names,rlang_fake_data_pronoun)
S3method(print,frame)
S3method(print,quosure)
S3method(print,quosures)
S3method(print,rlang_box_done)
S3method(print,rlang_box_splice)
S3method(print,rlang_data_pronoun)
S3method(print,rlang_envs)
S3method(print,rlang_error)
S3method(print,rlang_fake_data_pronoun)
S3method(print,rlang_lambda_function)
S3method(print,rlang_trace)
S3method(print,rlang_zap)
S3method(quantile,quosure)
S3method(str,quosure)
S3method(str,rlang_data_pronoun)
S3method(str,rlang_envs)
S3method(summary,rlang_error)
S3method(summary,rlang_trace)
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(.data)
export(.env)
export(UQ)
export(UQS)
export(abort)
export(are_na)
export(arg_match)
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_env)
export(as_environment)
export(as_function)
export(as_integer)
export(as_label)
export(as_list)
export(as_logical)
export(as_name)
export(as_overscope)
export(as_pairlist)
export(as_quosure)
export(as_quosures)
export(as_string)
export(as_utf8_character)
export(base_env)
export(bytes)
export(bytes_along)
export(bytes_len)
export(call2)
export(call_args)
export(call_args_names)
export(call_depth)
export(call_fn)
export(call_frame)
export(call_inspect)
export(call_modify)
export(call_name)
export(call_ns)
export(call_stack)
export(call_standardise)
export(caller_env)
export(caller_fn)
export(caller_frame)
export(calling)
export(catch_cnd)
export(child_env)
export(chr)
export(chr_along)
export(chr_len)
export(chr_unserialise_unicode)
export(cnd)
export(cnd_body)
export(cnd_entrace)
export(cnd_footer)
export(cnd_header)
export(cnd_message)
export(cnd_muffle)
export(cnd_signal)
export(cnd_type)
export(coerce_class)
export(coerce_type)
export(cpl)
export(cpl_along)
export(cpl_len)
export(ctxt_depth)
export(ctxt_frame)
export(ctxt_stack)
export(current_env)
export(current_fn)
export(current_frame)
export(dbl)
export(dbl_along)
export(dbl_len)
export(done)
export(dots_definitions)
export(dots_list)
export(dots_n)
export(dots_splice)
export(dots_values)
export(duplicate)
export(empty_env)
export(enexpr)
export(enexprs)
export(enquo)
export(enquos)
export(ensym)
export(ensyms)
export(entrace)
export(env)
export(env_bind)
export(env_bind_active)
export(env_bind_exprs)
export(env_bind_fns)
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_bury)
export(env_clone)
export(env_depth)
export(env_get)
export(env_get_list)
export(env_has)
export(env_inherits)
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(frame_position)
export(friendly_type)
export(get_env)
export(get_expr)
export(global_env)
export(global_frame)
export(has_length)
export(has_name)
export(have_name)
export(inform)
export(inherits_all)
export(inherits_any)
export(inherits_only)
export(int)
export(int_along)
export(int_len)
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_double)
export(is_bare_env)
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_binary_lang)
export(is_bool)
export(is_box)
export(is_bytes)
export(is_call)
export(is_call_stack)
export(is_callable)
export(is_character)
export(is_chr_na)
export(is_closure)
export(is_condition)
export(is_copyable)
export(is_cpl_na)
export(is_dbl_na)
export(is_definition)
export(is_dictionaryish)
export(is_done_box)
export(is_double)
export(is_empty)
export(is_env)
export(is_environment)
export(is_eval_stack)
export(is_expr)
export(is_expression)
export(is_false)
export(is_formula)
export(is_formulaish)
export(is_frame)
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_missing)
export(is_na)
export(is_named)
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_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_stack)
export(is_string)
export(is_symbol)
export(is_symbolic)
export(is_syntactic_literal)
export(is_true)
export(is_unary_lang)
export(is_vector)
export(is_weakref)
export(is_zap)
export(lang)
export(lang_args)
export(lang_args_names)
export(lang_fn)
export(lang_head)
export(lang_modify)
export(lang_name)
export(lang_standardise)
export(lang_tail)
export(last_error)
export(last_trace)
export(lgl)
export(lgl_along)
export(lgl_len)
export(list2)
export(list_along)
export(list_len)
export(ll)
export(local_bindings)
export(local_interactive)
export(local_options)
export(locally)
export(maybe_missing)
export(message_cnd)
export(missing_arg)
export(modify)
export(mut_attrs)
export(mut_node_caar)
export(mut_node_cadr)
export(mut_node_car)
export(mut_node_cdar)
export(mut_node_cddr)
export(mut_node_cdr)
export(mut_node_tag)
export(na_chr)
export(na_cpl)
export(na_dbl)
export(na_int)
export(na_lgl)
export(names2)
export(new_box)
export(new_call)
export(new_character)
export(new_character_along)
export(new_complex)
export(new_complex_along)
export(new_data_mask)
export(new_definition)
export(new_double)
export(new_double_along)
export(new_environment)
export(new_formula)
export(new_function)
export(new_integer)
export(new_integer_along)
export(new_language)
export(new_list)
export(new_list_along)
export(new_logical)
export(new_logical_along)
export(new_node)
export(new_overscope)
export(new_quosure)
export(new_quosures)
export(new_raw)
export(new_raw_along)
export(new_weakref)
export(node)
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(overscope_clean)
export(overscope_eval_next)
export(pairlist2)
export(parse_expr)
export(parse_exprs)
export(parse_quo)
export(parse_quos)
export(parse_quosure)
export(parse_quosures)
export(peek_option)
export(peek_options)
export(pkg_env)
export(pkg_env_name)
export(prepend)
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_lang)
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_along)
export(raw_len)
export(rep_along)
export(rep_named)
export(restarting)
export(return_from)
export(return_to)
export(rst_abort)
export(rst_exists)
export(rst_jump)
export(rst_list)
export(rst_maybe_jump)
export(scoped_bindings)
export(scoped_env)
export(scoped_envs)
export(scoped_interactive)
export(scoped_names)
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(stack_trim)
export(string)
export(switch_class)
export(switch_type)
export(sym)
export(syms)
export(trace_back)
export(trace_length)
export(type_of)
export(unbox)
export(vec_poke_n)
export(vec_poke_range)
export(warn)
export(warning_cnd)
export(with_abort)
export(with_bindings)
export(with_env)
export(with_handlers)
export(with_interactive)
export(with_options)
export(with_restarts)
export(wref_key)
export(wref_value)
export(zap)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(utils,str)
useDynLib(rlang, .registration = TRUE)
rlang/tools/ 0000755 0001762 0000144 00000000000 13366255562 012532 5 ustar ligges users rlang/tools/hasmacros.sh 0000755 0001762 0000144 00000000172 13361376453 015047 0 ustar ligges users #!/usr/bin/env sh
CODE="if (getRversion() < '3.3') stop('No macro support')"
"${R_HOME}/bin/R" -e "${CODE}" > /dev/null
rlang/README.md 0000644 0001762 0000144 00000004255 13567443762 012663 0 ustar ligges users rlang
=======================================================
[](https://github.com/r-lib/rlang)
[](https://codecov.io/github/r-lib/rlang?branch=master)
[](https://www.tidyverse.org/lifecycle/)
**Important**: The rlang API is still maturing. Please see
`?rlang::lifecycle` for the list of functions that are considered
stable.
## Overview
The rlang package provides tools to work with core language features
of R and the tidyverse:
* The __tidy eval__ framework, which is a well-founded system for
non-standard evaluation built on quasiquotation (`!!`) and
quoted arguments (`enquo()`). See .
* User-friendly __error reporting__ with backtraces and chained errors
(`abort()`, `trace_back()`, `with_abort()`).
* A consistent API for working with __base types__. Note that overall
this is a work in progress that is still in flux:
* Environments, e.g. `env()`, `env_has()`, `env_get()`,
`env_bind()`, `env_unbind()`, `env_print()`.
* Calls and symbols, e.g. `call2()`, `is_call()`, `sym()`, `syms()`.
* Functions, e.g. `new_function()`, `as_function()`. The latter
supports the purrr-style formula notation for lambda functions.
* Vectors, including construction (`lgl()`, `int()`, ...) and
predicates (`is_logical()`, `is_character()`).
* Attributes, e.g. `set_names()`.
## Installation
You can install the released version of rlang from CRAN with:
```r
install.packages("rlang")
```
Or install the development version from github with:
```r
# install.packages("remotes")
remotes::install_github("r-lib/rlang")
```
## Cheatsheet
rlang/man/ 0000755 0001762 0000144 00000000000 13614040227 012127 5 ustar ligges users rlang/man/prim_name.Rd 0000644 0001762 0000144 00000000516 13553606424 014400 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/scoped_interactive.Rd 0000644 0001762 0000144 00000002462 13604124170 016273 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{scoped_interactive}
\alias{scoped_interactive}
\alias{scoped_options}
\alias{scoped_bindings}
\title{Questioning \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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("questioning")}
These functions have been renamed to use the conventional \code{local_}
prefix. They will be deprecated in the next minor version of rlang.
}
rlang/man/env_inherits.Rd 0000644 0001762 0000144 00000000655 13405732277 015134 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 13604124170 013702 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 00000003027 13405732277 015725 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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/env_name.Rd 0000644 0001762 0000144 00000002374 13405732277 014227 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 00000012005 13604124170 013520 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{stack}
\alias{stack}
\alias{global_frame}
\alias{current_frame}
\alias{ctxt_frame}
\alias{call_frame}
\alias{ctxt_depth}
\alias{call_depth}
\alias{ctxt_stack}
\alias{call_stack}
\title{Call stack information}
\usage{
global_frame()
current_frame()
ctxt_frame(n = 1)
call_frame(n = 1, clean = TRUE)
ctxt_depth()
call_depth()
ctxt_stack(n = NULL, trim = 0)
call_stack(n = NULL, clean = TRUE)
}
\arguments{
\item{n}{The number of frames to go back in the stack.}
\item{clean}{Whether to post-process the call stack to clean
non-standard frames. If \code{TRUE}, suboptimal call-stack entries by
\code{\link[base:eval]{base::eval()}} will be cleaned up: the duplicate frame created by
\code{eval()} is eliminated.}
\item{trim}{The number of layers of intervening frames to trim off
the stack. See \code{\link[=stack_trim]{stack_trim()}} and examples.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
The \code{eval_} and \code{call_} families of functions provide a replacement
for the base R functions prefixed with \code{sys.} (which are all about
the context stack), as well as for \code{\link[=parent.frame]{parent.frame()}} (which is the
only base R function for querying the call stack). The context
stack includes all R-level evaluation contexts. It is linear in
terms of execution history but due to lazy evaluation it is
potentially nonlinear in terms of call history. The call stack
history, on the other hand, is homogenous.
}
\details{
\code{ctxt_frame()} and \code{call_frame()} return a \code{frame} object
containing the following fields: \code{expr} and \code{env} (call expression
and evaluation environment), \code{pos} and \code{caller_pos} (position of
current frame in the context stack and position of the caller), and
\code{fun} (function of the current frame). \code{ctxt_stack()} and
\code{call_stack()} return a list of all context or call frames on the
stack. Finally, \code{ctxt_depth()} and \code{call_depth()} report the
current context position or the number of calling frames on the
stack.
The base R functions take two sorts of arguments to indicate which
frame to query: \code{which} and \code{n}. The \code{n} argument is
straightforward: it's the number of frames to go down the stack,
with \code{n = 1} referring to the current context. The \code{which} argument
is more complicated and changes meaning for values lower than 1.
For the sake of consistency, the rlang functions all take the
same kind of argument \code{n}. This argument has a single meaning (the
number of frames to go down the stack) and cannot be lower than 1.
Note finally that \code{parent.frame(1)} corresponds to
\code{call_frame(2)$env}, as \code{n = 1} always refers to the current
frame. This makes the \verb{_frame()} and \verb{_stack()} functions
consistent: \code{ctxt_frame(2)} is the same as \code{ctxt_stack()[[2]]}.
Also, \code{ctxt_depth()} returns one more frame than
\code{\link[base:sys.nframe]{base::sys.nframe()}} because it counts the global frame. That is
consistent with the \verb{_stack()} functions which return the global
frame as well. This way, \code{call_stack(call_depth())} is the same as
\code{global_frame()}.
}
\section{Life cycle}{
These functions are soft-deprecated and replaced by \code{\link[=trace_back]{trace_back()}}.
}
\examples{
# Expressions within arguments count as contexts
identity(identity(ctxt_depth())) # returns 2
# But they are not part of the call stack because arguments are
# evaluated within the calling function (or the global environment
# if called at top level)
identity(identity(call_depth())) # returns 0
# The context stacks includes all intervening execution frames. The
# call stack doesn't:
f <- function(x) identity(x)
f(f(ctxt_stack()))
f(f(call_stack()))
g <- function(cmd) cmd()
f(g(ctxt_stack))
f(g(call_stack))
# The rlang _stack() functions return a list of frame
# objects. Use purrr::transpose() or index a field with
# purrr::map()'s to extract a particular field from a stack:
# stack <- f(f(call_stack()))
# purrr::map(stack, "env")
# purrr::transpose(stack)$expr
# current_frame() is an alias for ctxt_frame(1)
fn <- function() list(current = current_frame(), first = ctxt_frame(1))
fn()
# While current_frame() is the top of the stack, global_frame() is
# the bottom:
fn <- function() {
n <- ctxt_depth()
ctxt_frame(n)
}
identical(fn(), global_frame())
# ctxt_stack() returns a stack with all intervening frames. You can
# trim layers of intervening frames with the trim argument:
identity(identity(ctxt_stack()))
identity(identity(ctxt_stack(trim = 1)))
# ctxt_stack() is called within fn() with intervening frames:
fn <- function(trim) identity(identity(ctxt_stack(trim = trim)))
fn(0)
# We can trim the first layer of those:
fn(1)
# The outside intervening frames (at the fn() call site) are still
# returned, but can be trimmed as well:
identity(identity(fn(1)))
identity(identity(fn(2)))
g <- function(trim) identity(identity(fn(trim)))
g(2)
g(3)
}
\keyword{internal}
rlang/man/env_bind.Rd 0000644 0001762 0000144 00000013414 13604124167 014212 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}
\title{Bind symbols to objects in an environment}
\usage{
env_bind(.env, ...)
env_bind_lazy(.env, ..., .eval_env = caller_env())
env_bind_active(.env, ...)
}
\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.}
}
\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:makeActiveBinding]{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).
}
}
\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.
}
\section{Life cycle}{
Passing an environment wrapper like a formula or a function instead
of an environment is soft-deprecated as of rlang 0.3.0. This
internal genericity was causing confusion (see issue #427). You
should now extract the environment separately before calling these
functions.
}
\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
}
rlang/man/dots_definitions.Rd 0000644 0001762 0000144 00000002371 13604124167 015772 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dots.R
\name{dots_definitions}
\alias{dots_definitions}
\title{Capture definition objects}
\usage{
dots_definitions(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all")
)
}
\arguments{
\item{...}{For \code{enexprs()}, \code{ensyms()} and \code{enquos()}, names of
arguments to capture without evaluation (including \code{...}). For
\code{exprs()} and \code{quos()}, the expressions to capture unevaluated
(including expressions contained in \code{...}).}
\item{.named}{Whether to ensure all dots are named. Unnamed
elements are processed with \code{\link[=quo_name]{quo_name()}} to build a default
name. See also \code{\link[=quos_auto_name]{quos_auto_name()}}.}
\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. Note that \code{"trailing"}
applies only to arguments passed in \code{...}, not to named
arguments. On the other hand, \code{"all"} also applies to named
arguments.}
}
\description{
Capture definition objects
}
\section{Life cycle}{
\code{dots_definitions()} is experimental. Expect API changes.
}
\keyword{internal}
rlang/man/call_modify.Rd 0000644 0001762 0000144 00000006377 13604124167 014722 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}{Soft-deprecated as of rlang 0.3.0. Please
call \code{\link[=call_standardise]{call_standardise()}} 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_standardise]{call_standardise()}} before
modifying the call.
}
\section{Life cycle}{
\itemize{
\item The \code{.standardise} argument is deprecated as of rlang 0.3.0.
\item In rlang 0.2.0, \code{lang_modify()} was deprecated and renamed to
\code{call_modify()}. See lifecycle section in \code{\link[=call2]{call2()}} for more about
this change.
}
}
\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 because it might contain unmatched arguments:
user_call <- quote(matrix(x, nc = 3))
call_modify(user_call, ncol = 1)
# Standardising applies the usual argument matching rules:
user_call <- call_standardise(user_call)
user_call
call_modify(user_call, ncol = 1)
# You can also modify quosures inplace:
f <- quo(matrix(bar))
call_modify(f, quote(foo))
# 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 13405732277 013223 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 00000000433 13553606252 015107 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}
\title{Is object a condition?}
\usage{
is_condition(x)
}
\arguments{
\item{x}{An object to test.}
}
\description{
Is object a condition?
}
\keyword{internal}
rlang/man/scoped_env.Rd 0000644 0001762 0000144 00000001263 13500223442 014541 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{scoped_env}
\alias{scoped_env}
\alias{is_scoped}
\alias{scoped_envs}
\alias{scoped_names}
\title{Retired \code{scoped} functions}
\usage{
scoped_env(nm)
is_scoped(nm)
scoped_envs()
scoped_names()
}
\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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
These functions are deprecated as of rlang 0.3.0. They are replaced
by \code{\link[=is_attached]{is_attached()}}, ...
}
\keyword{internal}
rlang/man/cnd_message.Rd 0000644 0001762 0000144 00000004160 13565200230 014664 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)
cnd_header(cnd, ...)
cnd_body(cnd, ...)
cnd_footer(cnd, ...)
}
\arguments{
\item{cnd}{A condition object.}
\item{...}{Arguments passed to methods.}
}
\description{
\code{cnd_message()} assembles an error message from three generics:
\itemize{
\item \code{cnd_header()}
\item \code{cnd_body()}
\item \code{cnd_footer()}
}
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 empty character vectors. In general, methods for
these generics should return a character vector. The elements are
combined into a single string with a newline separator.
\code{cnd_message()} is automatically called by the \code{conditionMessage()}
for rlang errors. 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 \code{cnd_body()}}{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("experimental")}
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_body()}: 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 a \code{body} field in your error object
containing a static string, a \link[=as_function]{lambda-formula}, or a
function with the same signature as \code{cnd_body()}. This field
overrides the \code{cnd_body()} generic and makes it easy to generate an
error message tailored to the state in which the error was
constructed.
}
rlang/man/mut_node_car.Rd 0000644 0001762 0000144 00000002137 13500223442 015054 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{mut_node_car}
\alias{mut_node_car}
\alias{mut_node_cdr}
\alias{mut_node_caar}
\alias{mut_node_cadr}
\alias{mut_node_cdar}
\alias{mut_node_cddr}
\alias{mut_node_tag}
\title{Mutate node components}
\usage{
mut_node_car(x, newcar)
mut_node_cdr(x, newcdr)
mut_node_caar(x, newcar)
mut_node_cadr(x, newcar)
mut_node_cdar(x, newcdr)
mut_node_cddr(x, newcdr)
mut_node_tag(x, newtag)
}
\arguments{
\item{x}{A language or pairlist node. Note that these functions are
barebones and do not perform any type checking.}
\item{newcar}{The new CAR or CDR for the node. These
can be any R objects.}
\item{newcdr}{The new CAR or CDR for the node. These
can be any R objects.}
\item{newtag}{The new tag for the node. This should be a symbol.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
These functions were deprecated and renamed with \code{node_poke_}
prefix in rlang 0.2.0. This change follows a new naming convention
where mutation is referred to as "poking".
}
\keyword{internal}
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/caller_fn.Rd 0000644 0001762 0000144 00000001522 13554012136 014344 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stack.R
\name{caller_fn}
\alias{caller_fn}
\alias{current_fn}
\title{Get properties of the current or caller frame}
\usage{
caller_fn(n = 1)
current_fn()
}
\arguments{
\item{n}{The number of generations to go back.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("experimental")}
\itemize{
\item The current frame is the execution context of the function that
is currently being evaluated.
\item The caller frame is the execution context of the function that
called the function currently being evaluated.
}
See the \link[=stack]{call stack} topic for more information.
}
\section{Life cycle}{
These functions are experimental.
}
\seealso{
\code{\link[=caller_env]{caller_env()}} and \code{\link[=current_env]{current_env()}}
}
\keyword{internal}
rlang/man/sym.Rd 0000644 0001762 0000144 00000001113 13500434414 013221 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}
\title{Create a symbol or list of symbols}
\usage{
sym(x)
syms(x)
}
\arguments{
\item{x}{A string or list of strings.}
}
\value{
A symbol for \code{sym()} and a list of symbols for \code{syms()}.
}
\description{
These functions take strings as input and turn them into symbols.
}
\examples{
# 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()))
}
rlang/man/names2.Rd 0000644 0001762 0000144 00000001253 13405732277 013617 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/attr.R
\name{names2}
\alias{names2}
\title{Get names of a vector}
\usage{
names2(x)
}
\arguments{
\item{x}{A vector.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
This names getter 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{""}.
}
\section{Life cycle}{
\code{names2()} is stable.
}
\examples{
names2(letters)
# It also takes care of standardising missing names:
x <- set_names(1:3, c("a", NA, "b"))
names2(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 00000001544 13500223442 015712 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call_standardise}
\alias{call_standardise}
\title{Standardise a call}
\usage{
call_standardise(call, env = caller_env())
}
\arguments{
\item{call}{Can be a call or a quosure that wraps a call.}
\item{env}{The environment where to find the definition of the
function quoted in \code{call} in case \code{call} is not wrapped in a
quosure.}
}
\value{
A quosure if \code{call} is a quosure, a raw call otherwise.
}
\description{
This is essentially equivalent to \code{\link[base:match.call]{base::match.call()}}, but with
experimental handling of primitive functions.
}
\section{Life cycle}{
In rlang 0.2.0, \code{lang_standardise()} was deprecated and renamed to
\code{call_standardise()}. See lifecycle section in \code{\link[=call2]{call2()}} for more
about this change.
}
rlang/man/call_name.Rd 0000644 0001762 0000144 00000002206 13500223442 014325 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}
\title{Extract function name or namespaced of a call}
\usage{
call_name(call)
call_ns(call)
}
\arguments{
\item{call}{Can be a call or a quosure that wraps a call.}
}
\value{
A string with the function name, or \code{NULL} if the function
is anonymous.
}
\description{
Extract function name or namespaced of a call
}
\section{Life cycle}{
In rlang 0.2.0, \code{lang_name()} was deprecated and renamed to
\code{call_name()}. See lifecycle section in \code{\link[=call2]{call2()}} for more about
this change.
}
\examples{
# Extract the function name from quoted calls:
call_name(quote(foo(bar)))
call_name(quo(foo(bar)))
# Namespaced calls are correctly handled:
call_name(~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()))
}
\seealso{
\code{\link[=call_fn]{call_fn()}}
}
rlang/man/eval_tidy.Rd 0000644 0001762 0000144 00000012117 13604124170 014377 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 expression or 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
\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 \strong{data mask} with
\code{\link[=as_data_mask]{as_data_mask()}}. Evaluating in a data mask enables the following
features:
\itemize{
\item \link[=nse-defuse]{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 lets you be explicit about where to find
values and throw errors if you try to access non-existent values.
}
}
\section{Data masking}{
Data masking refers to how columns or objects inside \code{data} have
priority over objects defined in \code{env} (or in the quosure
environment, if applicable). If there is a column \code{var} in \code{data}
and an object \code{var} in \code{env}, and \code{expr} refers to \code{var}, the
column has priority:\preformatted{var <- "this one?"
data <- data.frame(var = rep("Or that one?", 3))
within <- function(data, expr) \{
eval_tidy(enquo(expr), data)
\}
within(data, toupper(var))
#> [1] "OR THAT ONE?" "OR THAT ONE?" "OR THAT ONE?"
}
Because the columns or objects in \code{data} are always found first,
before objects from \code{env}, we say that the data "masks" the
environment.
}
\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 quasiquotation
support, it is recommended to use \code{eval_tidy()} because users will
likely unquote 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. 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{Life cycle}{
\strong{rlang 0.3.0}
Passing an environment to \code{data} is deprecated. Please construct an
rlang data mask with \code{\link[=new_data_mask]{new_data_mask()}}.
}
\examples{
# With simple quoted expressions eval_tidy() works the same way as
# eval():
apple <- "apple"
kiwi <- "kiwi"
expr <- quote(paste(apple, kiwi))
expr
eval(expr)
eval_tidy(expr)
# Both accept a data mask as argument:
data <- list(apple = "CARROT", kiwi = "TOMATO")
eval(expr, data)
eval_tidy(expr, data)
# In addition eval_tidy() has support for quosures:
with_data <- function(data, expr) {
quo <- enquo(expr)
eval_tidy(quo, data)
}
with_data(NULL, apple)
with_data(data, apple)
with_data(data, list(apple, kiwi))
# Secondly eval_tidy() installs handy pronouns that allow users to
# be explicit about where to find symbols:
with_data(data, .data$apple)
with_data(data, .env$apple)
# Note that instead of using `.env` it is often equivalent and may
# be preferred to unquote a value. There are two differences. First
# unquoting happens earlier, when the quosure is created. Secondly,
# subsetting `.env` with the `$` operator may be brittle because
# `$` does not look through the parents of the environment.
#
# For instance using `.env$name` in a magrittr pipeline is an
# instance where this poses problem, because the magrittr pipe
# currently (as of v1.5.0) evaluates its operands in a *child* of
# the current environment (this child environment is where it
# defines the pronoun `.`).
\dontrun{
data \%>\% with_data(!!kiwi) # "kiwi"
data \%>\% with_data(.env$kiwi) # NULL
}
}
\seealso{
\link{nse-force} for the second leg of the tidy evaluation
framework.
}
rlang/man/rlang_backtrace_on_error.Rd 0000644 0001762 0000144 00000002744 13554012432 017434 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{
Errors thrown with \code{\link[=abort]{abort()}} automatically save a backtrace that
can be inspected by calling \code{\link[=last_error]{last_error()}}. Optionally, you can
also display the backtrace alongside the error message by setting
the option \code{rlang_backtrace_on_error} to one of the following
values:
\itemize{
\item \code{"reminder"}: Display a reminder that the backtrace can be
inspected by calling \code{\link[rlang:last_error]{rlang::last_error()}}.
\item \code{"branch"}: Display a simplified backtrace.
\item \code{"collapse"}: Display a collapsed backtrace tree.
\item \code{"full"}: Display the full backtrace tree.
}
}
\section{Promote base errors to rlang errors}{
Call \code{options(error = rlang::entrace)} to instrument base
errors with rlang features. This handler does two things:
\itemize{
\item It saves the base error as an rlang object. This allows you to
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.
}
}
\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/op-na-default.Rd 0000644 0001762 0000144 00000001262 13517571557 015074 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{
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}
}
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/exprs_auto_name.Rd 0000644 0001762 0000144 00000001724 13561023554 015620 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, width = NULL, printer = NULL)
quos_auto_name(quos, width = NULL)
}
\arguments{
\item{exprs}{A list of expressions.}
\item{width}{Deprecated. Maximum width of names.}
\item{printer}{Deprecated. A function that takes an expression
and converts it to a string. This function must take an
expression as the first argument and \code{width} as the second
argument.}
\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 13563536306 015372 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 00000004670 13604124167 013176 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-error.R, R/cnd.R
\name{error_cnd}
\alias{error_cnd}
\alias{cnd}
\alias{warning_cnd}
\alias{message_cnd}
\title{Create a condition object}
\usage{
error_cnd(.subclass = NULL, ..., message = "", trace = NULL, parent = NULL)
cnd(class, ..., message = "", .subclass)
warning_cnd(class = NULL, ..., message = "", .subclass)
message_cnd(class = NULL, ..., message = "", .subclass)
}
\arguments{
\item{.subclass}{This argument was renamed to \code{class} in rlang
0.4.2. It will be deprecated in the next major version. This is
for consistency with our conventions for class constructors
documented in \url{https://adv-r.hadley.nz/s3.html#s3-subclassing}.}
\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{trace}{A \code{trace} object created by \code{\link[=trace_back]{trace_back()}}.}
\item{parent}{A parent condition object created by \code{\link[=abort]{abort()}}.}
\item{class}{The condition subclass.}
}
\description{
These constructors make it easy to create subclassed conditions.
Conditions are objects that power the error system in R. They can
also be used for passing messages to pre-established handlers.
}
\details{
\code{cnd()} creates objects inheriting from \code{condition}. Conditions
created with \code{error_cnd()}, \code{warning_cnd()} and \code{message_cnd()}
inherit from \code{error}, \code{warning} or \code{message}.
}
\section{Lifecycle}{
The \code{.type} and \code{.msg} arguments have been renamed to \code{.subclass}
and \code{message}. They are deprecated as of rlang 0.3.0.
}
\examples{
# Create a condition inheriting from the s3 type "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 causes the handler
# to be called:
with_handlers(cnd_signal(cnd), foo = exiting(function(c) "caught!"))
# Handlers can be thrown or executed inplace. See with_handlers()
# documentation for more on this.
# Signalling an error condition aborts the current computation:
err <- error_cnd("foo", message = "I am an error")
try(cnd_signal(err))
}
\seealso{
\code{\link[=cnd_signal]{cnd_signal()}}, \code{\link[=with_handlers]{with_handlers()}}.
}
\keyword{internal}
rlang/man/lang.Rd 0000644 0001762 0000144 00000001367 13563531434 013356 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{lang}
\alias{lang}
\alias{new_language}
\title{Create a call}
\usage{
lang(.fn, ..., .ns = NULL)
new_language(head, tail = 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 13553606252 014663 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/are_na.Rd 0000644 0001762 0000144 00000003160 13554012136 013644 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("questioning")}
\code{are_na()} checks for missing values in a vector and is equivalent
to \code{\link[base:is.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/overscope_eval_next.Rd 0000644 0001762 0000144 00000001521 13604124170 016466 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{overscope_eval_next}
\alias{overscope_eval_next}
\title{Evaluate next quosure in a data mask}
\usage{
overscope_eval_next(overscope, quo, env = base_env())
}
\arguments{
\item{overscope}{A valid overscope containing bindings for \code{~},
\code{.top_env} and \verb{_F} and whose parents contain overscoped bindings
for tidy evaluation.}
\item{quo}{A quosure.}
\item{env}{The lexical enclosure in case \code{quo} is not a validly
scoped quosure. This is the \link[=base_env]{base environment} by
default.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
\code{overscope_eval_next()} is deprecated as of rlang 0.2.0. Please use
\code{eval_tidy()} to which you can now supply an overscope.
}
\keyword{internal}
rlang/man/op-get-attr.Rd 0000644 0001762 0000144 00000001472 13517627023 014574 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 13553605761 014233 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/caller_env.Rd 0000644 0001762 0000144 00000002311 13405732277 014540 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/env-special.R
\name{caller_env}
\alias{caller_env}
\alias{current_env}
\title{Get the current or caller environment}
\usage{
caller_env(n = 1)
current_env()
}
\arguments{
\item{n}{Number of frames to go back.}
}
\description{
\itemize{
\item The current environment is the execution environment of the
current function (the one currently being evaluated).
\item The caller environment is the execution environment of the
function that called the current function.
}
}
\examples{
# Let's create a function that returns its current environment and
# its caller environment:
fn <- function() list(current = current_env(), caller = caller_env())
# The current environment is an unique execution environment
# created when `fn()` was called. The caller environment is the
# global env because that's where we called `fn()`.
fn()
# Let's call `fn()` again but this time within a function:
g <- function() fn()
# Now the caller environment is also an unique execution environment.
# This is the exec env created by R for our call to g():
g()
}
\seealso{
\code{\link[=caller_frame]{caller_frame()}} and \code{\link[=current_frame]{current_frame()}}
}
rlang/man/empty_env.Rd 0000644 0001762 0000144 00000000732 13405732277 014441 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/quosure.Rd 0000644 0001762 0000144 00000010235 13561023554 014127 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/quo.R
\name{quosure}
\alias{quosure}
\alias{is_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 testers}
\usage{
is_quosure(x)
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{x}{An object to test.}
\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{
A quosure is a type of \link[=nse-defuse]{quoted expression} that includes
a reference to the context where it was created. A quosure is thus
guaranteed to evaluate in its original environment and can refer to
local objects.
You can access the quosure components (its expression and its
environment) with:
\itemize{
\item \code{\link[=get_expr]{get_expr()}} and \code{\link[=get_env]{get_env()}}. These getters also support other
kinds of objects such as formulas.
\item \code{quo_get_expr()} and \code{quo_get_env()}. These getters only work
with quosures and throw an error with other types of input.
}
Test if an object is a quosure with \code{is_quosure()}. If you know an
object is a quosure, use the \code{quo_} prefixed predicates to check
its contents, \code{quo_is_missing()}, \code{quo_is_symbol()}, etc.
}
\section{Quosured constants}{
A quosure usually does not carry environments for \link[=is_syntactic_literal]{constant objects} like strings or numbers. \code{\link[=quo]{quo()}} and
\code{\link[=enquo]{enquo()}} only capture an environment for \link[=is_symbolic]{symbolic expressions}. For instance, all of these return the
\link[=empty_env]{empty environment}:\preformatted{quo_get_env(quo("constant"))
quo_get_env(quo(100))
quo_get_env(quo(NA))
}
On the other hand, quosures capture the environment of symbolic
expressions, i.e. expressions whose meaning depends on the
environment in which they are evaluated and what objects are
defined there:\preformatted{quo_get_env(quo(some_object))
quo_get_env(quo(some_function()))
}
}
\section{Empty quosures}{
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.
}
\section{Life cycle}{
\itemize{
\item \code{is_quosure()} is stable.
\item \code{quo_get_expr()} and \code{quo_get_env()} are stable.
}
}
\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{
\code{\link[=quo]{quo()}} for creating quosures by quotation; \code{\link[=as_quosure]{as_quosure()}}
and \code{\link[=new_quosure]{new_quosure()}} for constructing quosures manually.
}
rlang/man/is_weakref.Rd 0000644 0001762 0000144 00000000420 13500531447 014534 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 00000001723 13500223442 014013 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{call_fn}
\alias{call_fn}
\title{Extract function from a call}
\usage{
call_fn(call, env = caller_env())
}
\arguments{
\item{call}{Can be a call or a quosure that wraps a call.}
\item{env}{The environment where to find the definition of the
function quoted in \code{call} in case \code{call} is not wrapped in a
quosure.}
}
\description{
If a frame or formula, the function will be retrieved from the
associated environment. Otherwise, it is looked up in the calling
frame.
}
\section{Life cycle}{
In rlang 0.2.0, \code{lang_fn()} was deprecated and renamed to
\code{call_fn()}. See lifecycle section in \code{\link[=call2]{call2()}} for more about this
change.
}
\examples{
# Extract from a quoted call:
call_fn(quote(matrix()))
call_fn(quo(matrix()))
# Extract the calling function
test <- function() call_fn(call_frame())
test()
}
\seealso{
\code{\link[=call_name]{call_name()}}
}
rlang/man/rst_list.Rd 0000644 0001762 0000144 00000002321 13563532074 014270 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-restarts.R
\name{rst_list}
\alias{rst_list}
\alias{rst_exists}
\alias{rst_jump}
\alias{rst_maybe_jump}
\title{Restarts utilities}
\usage{
rst_list()
rst_exists(.restart)
rst_jump(.restart, ...)
rst_maybe_jump(.restart, ...)
}
\arguments{
\item{.restart}{The name of a restart.}
\item{...}{<\link[=dyn-dots]{dynamic}> Arguments passed on to the
restart function.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("questioning")}
Restarts are named jumping points established by \code{\link[=with_restarts]{with_restarts()}}.
\code{rst_list()} returns the names of all restarts currently
established. \code{rst_exists()} checks if a given restart is
established. \code{rst_jump()} stops execution of the current function
and jumps to a restart point. If the restart does not exist, an
error is thrown. \code{rst_maybe_jump()} first checks that a restart
exists before jumping.
}
\section{Life cycle}{
All the restart functions are in the questioning stage. It is not
clear yet whether we want to recommend restarts as a style of
programming in R.
}
\seealso{
\code{\link[=with_restarts]{with_restarts()}}
}
\keyword{internal}
rlang/man/invoke.Rd 0000644 0001762 0000144 00000005140 13604124170 013710 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval.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}{A function to invoke. Can be a function object or the
name of a function in scope of \code{.env}.}
\item{.args, ...}{List of arguments (possibly named) to be passed to
\code{.fn}.}
\item{.env}{The environment in which to call \code{.fn}.}
\item{.bury}{A character vector of length 2. The first string
specifies which name should the function have in the call
recorded in the evaluation stack. The second string specifies a
prefix for the argument names. Set \code{.bury} to \code{NULL} if you
prefer to inline the function and its arguments in the call.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("soft-deprecated")}
Normally, you invoke a R function by typing arguments manually. A
powerful alternative is to call a function with a list of arguments
assembled programmatically. This is the purpose of \code{invoke()}.
}
\details{
Technically, \code{invoke()} is basically a version of \code{\link[base:do.call]{base::do.call()}}
that creates cleaner call traces because it does not inline the
function and the arguments in the call (see examples). To achieve
this, \code{invoke()} creates a child environment of \code{.env} with \code{.fn}
and all arguments bound to new symbols (see \code{\link[=env_bury]{env_bury()}}). It then
uses the same strategy as \code{\link[=eval_bare]{eval_bare()}} to evaluate with minimal
noise.
}
\section{Life cycle}{
\code{invoke()} is soft-deprecated in favour of \code{\link[=exec]{exec()}}. Now that we
understand better the interaction between unquoting and dots
capture, we can take a simpler approach in \code{exec()}.
If you need finer control over the generated call, you should construct
an environment and call yourself, manually burying large objects
or complex expressions.
}
\examples{
# invoke() has the same purpose as do.call():
invoke(paste, letters)
# But it creates much cleaner calls:
invoke(call_inspect, mtcars)
# and stacktraces:
fn <- function(...) sys.calls()
invoke(fn, list(mtcars))
# Compare to do.call():
do.call(call_inspect, mtcars)
do.call(fn, list(mtcars))
# Specify the function name either by supplying a string
# identifying the function (it should be visible in .env):
invoke("call_inspect", letters)
# Or by changing the .bury argument, with which you can also change
# the argument prefix:
invoke(call_inspect, mtcars, .bury = c("inspect!", "col"))
}
\keyword{internal}
rlang/man/as_environment.Rd 0000644 0001762 0000144 00000002760 13500404445 015452 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}.
}
\section{Life cycle}{
\code{as_env()} was soft-deprecated and renamed to \code{as_environment()} in
rlang 0.2.0. This is for consistency as type predicates should not
be abbreviated.
}
\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 13351410454 014067 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 00000003706 13604124170 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, width = peek_option("width"))
expr_deparse(x, width = peek_option("width"))
}
\arguments{
\item{x}{An object or expression to print.}
\item{width}{The width of the deparsed or printed expression.
Defaults to the global option \code{width}.}
}
\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 00000003343 13561023554 014765 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-force.R
\name{expr_interp}
\alias{expr_interp}
\title{Process unquote operators in a captured expression}
\usage{
expr_interp(x, env = NULL)
}
\arguments{
\item{x}{A function, raw expression, or formula to interpolate.}
\item{env}{The environment in which unquoted expressions should be
evaluated. By default, the formula or closure environment if a
formula or a function, or the current environment otherwise.}
}
\description{
While all capturing functions in the tidy evaluation framework
perform unquote on capture (most notably \code{\link[=quo]{quo()}}),
\code{expr_interp()} manually processes unquoting operators in
expressions that are already captured. \code{expr_interp()} should be
called in all user-facing functions expecting a formula as argument
to provide the same quasiquotation functionality as NSE functions.
}
\examples{
# All tidy NSE functions like quo() unquote on capture:
quo(list(!!(1 + 2)))
# expr_interp() is meant to provide the same functionality when you
# have a formula or expression that might contain unquoting
# operators:
f <- ~list(!!(1 + 2))
expr_interp(f)
# Note that only the outer formula is unquoted (which is a reason
# to use expr_interp() as early as possible in all user-facing
# functions):
f <- ~list(~!!(1 + 2), !!(1 + 2))
expr_interp(f)
# Another purpose for expr_interp() is to interpolate a closure's
# body. This is useful to inline a function within another. The
# important limitation is that all formal arguments of the inlined
# function should be defined in the receiving function:
other_fn <- function(x) toupper(x)
fn <- expr_interp(function(x) {
x <- paste0(x, "_suffix")
!!! body(other_fn)
})
fn
fn("foo")
}
rlang/man/env_get.Rd 0000644 0001762 0000144 00000002352 13405732277 014062 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)
env_get_list(env = caller_env(), nms, default, inherit = FALSE)
}
\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.}
}
\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")
}
rlang/man/last_error.Rd 0000644 0001762 0000144 00000001015 13552300110 014556 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-abort.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 thrown with \code{\link[=abort]{abort()}}. 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.
}
}
rlang/man/new_call.Rd 0000644 0001762 0000144 00000000743 13351410763 014212 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[=node]{node list} of
arguments.}
}
\description{
Create a new call from components
}
\keyword{internal}
rlang/man/splice.Rd 0000644 0001762 0000144 00000010450 13604124167 013702 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 passed in
dots. When \code{TRUE} and a \verb{<-} call is detected, a warning is
issued to advise users to use \code{=} if they meant to match a
function parameter, or wrap the \verb{<-} call in braces otherwise.
This ensures assignments are explicit.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 13500531447 014722 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/catch_cnd.Rd 0000644 0001762 0000144 00000001477 13607306553 014346 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 00000010172 13500437433 015523 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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:as.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 00000001447 13604124170 014427 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
}
}
rlang/man/dots_n.Rd 0000644 0001762 0000144 00000000653 13553606643 013724 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 00000003564 13413472702 014423 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:as.symbol]{base::as.symbol()}} and \code{\link[base:as.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 13405732277 015065 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 00000004114 13604124167 014753 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 passed in
dots. When \code{TRUE} and a \verb{<-} call is detected, a warning is
issued to advise users to use \code{=} if they meant to match a
function parameter, or wrap the \verb{<-} call in 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/op-definition.Rd 0000644 0001762 0000144 00000003371 13604124170 015165 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/operators.R
\name{op-definition}
\alias{op-definition}
\alias{is_definition}
\alias{new_definition}
\alias{is_formulaish}
\title{Definition operator}
\usage{
is_definition(x)
new_definition(lhs, rhs, env = caller_env())
is_formulaish(x, scoped = NULL, lhs = NULL)
}
\arguments{
\item{x}{An object to test.}
\item{lhs, rhs}{Expressions for the LHS and RHS of the definition.}
\item{env}{The evaluation environment bundled with the definition.}
}
\description{
The definition operator is typically used in DSL packages like
\code{ggvis} and \code{data.table}. It is also used in the tidyverse as a way
of unquoting names (see \link{nse-force}).
\itemize{
\item \code{is_definition()} returns \code{TRUE} for calls to \verb{:=}.
\item \code{is_formulaish()} returns \code{TRUE} for both formulas and
colon-equals operators.
}
}
\details{
The recommended way to use it is to capture arguments as
expressions or quosures. You can then give a special function
definition for the \verb{:=} symbol in an overscope. Note that if you
capture dots with \code{\link[=exprs]{exprs()}} or \code{\link[=quos]{quos()}}, you need to disable
interpretation of \verb{:=} by setting \code{.unquote_names} to \code{FALSE}.
From rlang and data.table perspectives, this operator is not meant
to be evaluated directly at top-level which is why the exported
definitions issue an error.
}
\section{Life cycle}{
These functions are experimental.
}
\examples{
# A predicate is provided to distinguish formulas from the
# colon-equals operator:
is_definition(quote(a := b))
is_definition(a ~ b)
# is_formulaish() tests for both definitions and formulas:
is_formulaish(a ~ b)
is_formulaish(quote(a := b))
}
\keyword{internal}
rlang/man/env_names.Rd 0000644 0001762 0000144 00000003254 13604124167 014402 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 00000003756 13553606252 014112 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.}
\usage{
na_lgl
na_int
na_dbl
na_chr
na_cpl
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 00000007512 13604132570 013462 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 dots in a list}
\usage{
list2(...)
dots_list(
...,
.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{.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 passed in
dots. When \code{TRUE} and a \verb{<-} call is detected, a warning is
issued to advise users to use \code{=} if they meant to match a
function parameter, or wrap the \verb{<-} call in 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/pairlist2.Rd 0000644 0001762 0000144 00000001445 13563532074 014344 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/call.R
\name{pairlist2}
\alias{pairlist2}
\title{Create pairlists with splicing support}
\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 00000003743 13604124170 016456 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 00000005260 13413472574 014377 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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()}}
}
rlang/man/has_length.Rd 0000644 0001762 0000144 00000001361 13553605761 014547 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/tidyeval-data.Rd 0000644 0001762 0000144 00000002532 13610366361 015156 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval-tidy.R
\docType{data}
\name{tidyeval-data}
\alias{tidyeval-data}
\alias{.data}
\alias{.env}
\title{Data pronouns for tidy evaluation}
\format{An object of class \code{rlang_fake_data_pronoun} of length .}
\usage{
.data
.env
}
\description{
These pronouns allow you to be explicit about where to find objects
when programming with 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)
}
The \code{.data} object exported from rlang is also useful to import in
your package namespace to avoid a \verb{R CMD check} note when referring
to objects from the data mask.
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.
}
\keyword{datasets}
rlang/man/wref_key.Rd 0000644 0001762 0000144 00000000663 13500531447 014241 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 00000003043 13500416332 016425 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_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_integer(x, n = NULL)
is_bare_numeric(x, n = NULL)
is_bare_character(x, n = NULL, encoding = 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.}
\item{encoding}{Defunct as of rlang 0.4.0.}
}
\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/as_box.Rd 0000644 0001762 0000144 00000001477 13407134203 013700 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 00000003045 13351410654 015117 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:inherits]{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 00000002606 13553605761 014236 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 00000001011 13405732277 014372 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.
}
\examples{
env <- env(!!! mtcars)
clone <- env_clone(env)
identical(env, clone)
identical(env$cyl, clone$cyl)
}
rlang/man/as_bytes.Rd 0000644 0001762 0000144 00000000766 13500441351 014235 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils-encoding.R
\name{as_bytes}
\alias{as_bytes}
\title{Coerce to a raw vector}
\usage{
as_bytes(x)
}
\arguments{
\item{x}{A string.}
}
\value{
A raw vector of bytes.
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("experimental")}
This currently only works with strings, and returns its hexadecimal
representation.
}
\section{Life cycle}{
Raw vector functions are experimental.
}
\keyword{internal}
rlang/man/with_env.Rd 0000644 0001762 0000144 00000003722 13553606424 014256 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/eval.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{
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()}}).
}
\details{
\code{locally()} is equivalent to the base function
\code{\link[base:local]{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.
}
\section{Life cycle}{
These functions are experimental. Expect API changes.
}
\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/type_of.Rd 0000644 0001762 0000144 00000003003 13500520041 014046 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{type_of}
\alias{type_of}
\title{Base type of an object}
\usage{
type_of(x)
}
\arguments{
\item{x}{An R object.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("soft-deprecated")}
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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".
}
}
\section{Life cycle}{
\code{type_of()} is an experimental function. Expect API changes.
}
\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 00000003235 13500416332 015521 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_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_character(x, n = NULL, encoding = 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.}
\item{encoding}{Defunct as of rlang 0.4.0.}
}
\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 00000004264 13563530577 014753 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}
\alias{as_closure}
\title{Convert to function or closure}
\usage{
as_function(x, env = caller_env())
is_lambda(x)
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.
Lambdas currently do not support \link{nse-force},
due to the way the arguments are handled internally.}
\item{env}{Environment in which to fetch the function in case \code{x}
is a string.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
\itemize{
\item \code{as_function()} transforms a one-sided formula into a function.
This powers the lambda syntax in packages like purrr.
\item \code{as_closure()} first passes its argument to \code{as_function()}. If
the result is a primitive function, it regularises it to a proper
\link{closure} (see \code{\link[=is_function]{is_function()}} about primitive functions). Some
special control flow primitives like \code{if}, \code{for}, or \code{break}
can't be coerced to a closure.
}
}
\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"))
# 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(`~`)
# Use a regular function for tidy evaluation, also when calling functions
# that use tidy evaluation:
## Bad:
e <- as_function(~ as_label(ensym(.x)))
## Good:
e <- as_function(function(x) as_label(ensym(x)))
e(y)
}
rlang/man/trace_back.Rd 0000644 0001762 0000144 00000005513 13522760342 014505 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.}
\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{summary()} method of this object will reveal.
}
\details{
\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/with_abort.Rd 0000644 0001762 0000144 00000002741 13552030327 014565 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-entrace.R
\name{with_abort}
\alias{with_abort}
\title{Promote all errors to rlang errors}
\usage{
with_abort(expr, classes = "error")
}
\arguments{
\item{expr}{An expression run in a context where errors are
promoted to rlang errors.}
\item{classes}{Character vector of condition classes that should be
promoted to rlang errors.}
}
\description{
\code{with_abort()} promotes conditions as if they were thrown with
\code{\link[=abort]{abort()}}. These errors embed a \link[=trace_back]{backtrace}. They are
particularly suitable to be set as \emph{parent errors} (see \code{parent}
argument of \code{\link[=abort]{abort()}}).
}
\details{
\code{with_abort()} installs a \link[=calling]{calling handler} for errors and
rethrows non-rlang errors with \code{\link[=abort]{abort()}}. However, error handlers
installed \emph{within} \code{with_abort()} have priority. For this reason,
you should use \code{\link[=tryCatch]{tryCatch()}} and \link{exiting} handlers outside
\code{with_abort()} rather than inside.
}
\examples{
# with_abort() automatically casts simple errors thrown by stop()
# to rlang errors. It is is handy for rethrowing low level
# errors. The backtraces are then segmented between the low level
# and high level contexts.
f <- function() g()
g <- function() stop("Low level error")
high_level <- function() {
with_handlers(
with_abort(f()),
error = ~ abort("High level error", parent = .)
)
}
}
rlang/man/as_utf8_character.Rd 0000644 0001762 0000144 00000003333 13604124170 016004 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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)
as_bytes(utf8)
}
\keyword{internal}
rlang/man/env_has.Rd 0000644 0001762 0000144 00000001703 13405732277 014055 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 containing the names of the bindings
to remove.}
\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/cnd_muffle.Rd 0000644 0001762 0000144 00000005253 13553606643 014541 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.}
}
\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:suppressMessages]{base::suppressMessages()}} and
\code{\link[base:suppressWarnings]{base::suppressWarnings()}}.
\item Bare conditions signalled with \code{signal()} or \code{\link[=cnd_signal]{cnd_signal()}}. Note
that conditions signalled with \code{\link[base:signalCondition]{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:tryCatch]{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 00000006106 13604124167 013423 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:as.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 and convenient 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")
ns_call <- as.call(list(as.name("::"), as.name("list"), as.name("base")))
as.call(list(ns_call, 1, 2))
}
\item \code{call2()} has \link[=list2]{tidy dots} support and you can splice lists
of arguments with \verb{!!!}. With base R, you need to use \code{as.call()}
instead of \code{call()} if the arguments are in a list.\preformatted{args <- list(na.rm = TRUE, trim = 0)
call2("mean", 1:10, !!!args)
as.call(c(list(as.name("mean"), 1:10), args))
}
}
}
\section{Life cycle}{
In rlang 0.2.0 \code{lang()} was soft-deprecated and renamed to
\code{call2()}.
In early versions of rlang calls were called "language" objects in
order to follow the R type nomenclature as returned by
\code{\link[base:typeof]{base::typeof()}}. The goal was to avoid adding to the confusion
between S modes and R types. With hindsight we find it is better to
use more meaningful type names.
}
\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/is_stack.Rd 0000644 0001762 0000144 00000000630 13554012136 014216 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{is_stack}
\alias{is_stack}
\alias{is_eval_stack}
\alias{is_call_stack}
\title{Is object a stack?}
\usage{
is_stack(x)
is_eval_stack(x)
is_call_stack(x)
}
\arguments{
\item{x}{An object to test}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("soft-deprecated")}
}
\keyword{internal}
rlang/man/env.Rd 0000644 0001762 0000144 00000012453 13604124167 013220 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. Can be an object
supported by \code{\link[=as_environment]{as_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/wch/R6}{R6 package}
and the \href{http://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/missing_arg.Rd 0000644 0001762 0000144 00000007756 13446672557 014763 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.
\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{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. This means that expressions like \code{x[[1]] <- missing_arg()}
are perfectly safe. Likewise, \code{x[[1]]} is safe even if the result
is the missing object.
However, as soon as the missing argument is passed down between
functions through an argument, you're at risk of triggering a
missing error. This is because arguments are passed through
symbols. 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.
\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.
}
\section{Life cycle}{
\itemize{
\item \code{missing_arg()} and \code{is_missing()} are stable.
\item Like the rest of rlang, \code{maybe_missing()} is maturing.
}
}
\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/as_data_mask.Rd 0000644 0001762 0000144 00000021003 13604124170 015020 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, parent = NULL)
as_data_pronoun(data)
new_data_mask(bottom, top = bottom, parent = NULL)
}
\arguments{
\item{data}{A data frame or named vector of masking data.}
\item{parent}{Deprecated. This argument no longer has any effect.
The parent of the data mask is determined from either:
\itemize{
\item The \code{env} argument of \code{eval_tidy()}
\item Quosure environments when applicable
}}
\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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
A 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.
}
\section{Life cycle}{
The \code{parent} argument no longer has any effect and is defunct as of
rlang 0.4.0. The parent of the data mask is determined from either:
\itemize{
\item The \code{env} argument of \code{eval_tidy()}
\item Quosure environments when applicable
}
Passing environments to \code{as_data_mask()} is deprecated as of rlang
0.3.0. Please use \code{new_data_mask()} instead.
\strong{rlang 0.2.0}
In early versions of rlang data masks were called overscopes. We
think data mask is a more natural name in R. It makes reference to
masking in the search path which occurs through the same mechanism
(in technical terms, lexical scoping with hierarchically nested
environments). We say that objects from user data mask objects
in the current environment.
Following this change in terminology, \code{as_overscope()} and
\code{new_overscope()} were deprecated in rlang 0.2.0 in favour of
\code{as_data_mask()} and \code{new_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 the 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 13457603056 014061 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 lookep 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 00000002635 13604124170 017310 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{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("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 00000002332 13500432472 014546 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 containing the names of the bindings
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{
data <- set_names(as.list(letters), letters)
env_bind(environment(), !!! data)
env_has(environment(), letters)
# env_unbind() removes bindings:
env_unbind(environment(), letters)
env_has(environment(), letters)
# With inherit = TRUE, it removes bindings in parent environments
# as well:
parent <- child_env(NULL, foo = "a")
env <- child_env(parent, foo = "b")
env_unbind(env, "foo", inherit = TRUE)
env_has(env, "foo", inherit = TRUE)
}
rlang/man/is_expression.Rd 0000644 0001762 0000144 00000007755 13351410654 015331 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{
\code{is_expression()} tests for expressions, the set of objects that can be
obtained from parsing R code. An expression can be one of two
things: either a symbolic object (for which \code{is_symbolic()} returns
\code{TRUE}), or a syntactic literal (testable with
\code{is_syntactic_literal()}). Technically, calls can contain any R
object, not necessarily symbolic objects or syntactic
literals. However, this only happens in artificial
situations. Expressions as we define them only contain numbers,
strings, \code{NULL}, symbols, and calls: this is the complete set of R
objects that can be created when R parses source code (e.g. from
using \code{\link[=parse_expr]{parse_expr()}}).
Note that we are using the term expression in its colloquial sense
and not to refer to \code{\link[=expression]{expression()}} vectors, a data type that wraps
expressions in a vector and which isn't used much in modern R code.
}
\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).
Pairlists are also a kind of language objects. However, since they
are mostly an internal data structure, \code{is_expression()} returns \code{FALSE}
for pairlists. You can use \code{is_pairlist()} to explicitly check for
them. Pairlists are the data structure for function arguments. They
usually do not arise from R code because subsetting a call is a
type-preserving operation. However, you can obtain the pairlist of
arguments by taking the CDR of the call object from C code. The
rlang function \code{\link[=node_cdr]{node_cdr()}} will do it from R. Another way in
which pairlist of arguments arise is by extracting the argument
list of a closure with \code{\link[base:formals]{base::formals()}} or \code{\link[=fn_fmls]{fn_fmls()}}.
}
\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/is_call.Rd 0000644 0001762 0000144 00000005632 13604124167 014037 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. If a formula, the right-hand side is
extracted.}
\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.
}
\section{Life cycle}{
\code{is_lang()} has been soft-deprecated and renamed to \code{is_call()} in
rlang 0.2.0 and similarly for \code{is_unary_lang()} and
\code{is_binary_lang()}. This renaming follows the general switch from
"language" to "call" in the rlang type nomenclature. See lifecycle
section in \code{\link[=call2]{call2()}}.
}
\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/caller_frame.Rd 0000644 0001762 0000144 00000000534 13500223442 015030 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{caller_frame}
\alias{caller_frame}
\title{Get caller frame}
\usage{
caller_frame(n = 1)
}
\arguments{
\item{n}{Number of frames to go back.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
}
\keyword{internal}
rlang/man/friendly_type.Rd 0000644 0001762 0000144 00000001132 13504161362 015272 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/types.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{
Format a type for error messages
}
\section{Life cycle}{
\itemize{
\item \code{friendly_type()} is experimental.
}
}
\examples{
friendly_type("logical")
friendly_type("integer")
friendly_type("string")
}
\keyword{internal}
rlang/man/set_names.Rd 0000644 0001762 0000144 00000002764 13500131074 014400 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}.
You can specify names in the following ways:
\itemize{
\item If you do nothing, \code{x} will be named with itself.
\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 If \code{nm} is \code{NULL}, the names are removed (if present).
\item In all other cases, \code{nm} and \code{...} are coerced to character.
}}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
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")
}
rlang/man/is_function.Rd 0000644 0001762 0000144 00000010251 13517571557 014756 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
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 (see \code{\link[=ctxt_stack]{ctxt_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)
# Primitive functions never appear in evaluation stacks:
is_primitive(base::`[[`)
is_primitive(base::list)
list(ctxt_stack())[[1]]
# While closures do:
identity(identity(ctxt_stack()))
# 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/frame_position.Rd 0000644 0001762 0000144 00000003630 13500223442 015432 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lifecycle-retired.R
\name{frame_position}
\alias{frame_position}
\title{Find the position or distance of a frame on the evaluation stack}
\usage{
frame_position(frame, from = c("global", "current"))
}
\arguments{
\item{frame}{The environment of a frame. Can be any object with a
\code{\link[=get_env]{get_env()}} method. Note that for frame objects, the position from
the global frame is simply \code{frame$pos}. Alternatively, \code{frame}
can be an integer that represents the position on the stack (and
is thus returned as is if \code{from} is "global".}
\item{from}{Whether to compute distance from the global frame (the
bottom of the evaluation stack), or from the current frame (the
top of the evaluation stack).}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("deprecated")}
The frame position on the stack can be computed by counting frames
from the global frame (the bottom of the stack, the default) or
from the current frame (the top of the stack).
}
\details{
While this function returns the position of the frame on the
evaluation stack, it can safely be called with intervening frames
as those will be discarded.
}
\section{Life cycle}{
These functions are deprecated and replaced by \code{\link[=trace_back]{trace_back()}}.
}
\examples{
fn <- function() g(environment())
g <- function(env) frame_position(env)
# frame_position() returns the position of the frame on the evaluation stack:
fn()
identity(identity(fn()))
# Note that it trims off intervening calls before counting so you
# can safely nest it within other calls:
g <- function(env) identity(identity(frame_position(env)))
fn()
# You can also ask for the position from the current frame rather
# than the global frame:
fn <- function() g(environment())
g <- function(env) h(env)
h <- function(env) frame_position(env, from = "current")
fn()
}
\keyword{internal}
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 00000002576 13565177531 016701 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. Elements named as
\code{x} or \code{i} are prefixed with the corresponding bullet.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("experimental")}
\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 Elements named \code{"i"} are bulleted with a blue "info" symbol.
\item Elements named \code{"x"} are bulleted with a red "cross" symbol.
\item Unnamed elements are bulleted with a "*" symbol.
}
This experimental infrastructure is based on the idea that
sentences in error messages are best kept short and simple. From
this point of view, 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()}}.
}
rlang/man/fn_env.Rd 0000644 0001762 0000144 00000002015 13351410454 013670 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
(see \code{\link[=ctxt_stack]{ctxt_stack()}}) 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/with_restarts.Rd 0000644 0001762 0000144 00000010226 13604124167 015326 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cnd-restarts.R
\name{with_restarts}
\alias{with_restarts}
\title{Establish a restart point on the stack}
\usage{
with_restarts(.expr, ...)
}
\arguments{
\item{.expr}{An expression to execute with new restarts established
on the stack. This argument is passed by expression and supports
\link[=nse-force]{unquoting}. It is evaluated in a context where
restarts are established.}
\item{...}{<\link[=dyn-dots]{dynamic}> Named restart functions. The
name is taken as the restart name and the function is executed
after the jump.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("questioning")}
Restart points are named functions that are established with
\code{with_restarts()}. Once established, you can interrupt the normal
execution of R code, jump to the restart, and resume execution from
there. Each restart is established along with a restart function
that is executed after the jump and that provides a return value
from the establishing point (i.e., a return value for
\code{with_restarts()}).
}
\details{
Restarts are not the only way of jumping to a previous call frame
(see \code{\link[=return_from]{return_from()}} or \code{\link[=return_to]{return_to()}}). However, they have the
advantage of being callable by name once established.
}
\section{Life cycle}{
All the restart functions are in the questioning stage. It is not
clear yet whether we want to recommend restarts as a style of
programming in R.
}
\examples{
# Restarts are not the only way to jump to a previous frame, but
# they have the advantage of being callable by name:
fn <- function() with_restarts(g(), my_restart = function() "returned")
g <- function() h()
h <- function() { rst_jump("my_restart"); "not returned" }
fn()
# Whereas a non-local return requires to manually pass the calling
# frame to the return function:
fn <- function() g(current_env())
g <- function(env) h(env)
h <- function(env) { return_from(env, "returned"); "not returned" }
fn()
# rst_maybe_jump() checks that a restart exists before trying to jump:
fn <- function() {
g()
cat("will this be called?\n")
}
g <- function() {
rst_maybe_jump("my_restart")
cat("will this be called?\n")
}
# Here no restart are on the stack:
fn()
# If a restart point called `my_restart` was established on the
# stack before calling fn(), the control flow will jump there:
rst <- function() {
cat("restarting...\n")
"return value"
}
with_restarts(fn(), my_restart = rst)
# Restarts are particularly useful to provide alternative default
# values when the normal output cannot be computed:
fn <- function(valid_input) {
if (valid_input) {
return("normal value")
}
# We decide to return the empty string "" as default value. An
# altenative strategy would be to signal an error. In any case,
# we want to provide a way for the caller to get a different
# output. For this purpose, we provide two restart functions that
# returns alternative defaults:
restarts <- list(
rst_empty_chr = function() character(0),
rst_null = function() NULL
)
with_restarts(splice(restarts), .expr = {
# Signal a typed condition to let the caller know that we are
# about to return an empty string as default value:
cnd_signal("default_empty_string")
# If no jump to with_restarts, return default value:
""
})
}
# Normal value for valid input:
fn(TRUE)
# Default value for bad input:
fn(FALSE)
# Change the default value if you need an empty character vector by
# defining a calling handler that jumps to the restart. It has to
# be calling because exiting handlers jump to the place where they
# are established before being executed, and the restart is not
# defined anymore at that point:
rst_handler <- calling(function(c) rst_jump("rst_empty_chr"))
with_handlers(fn(FALSE), default_empty_string = rst_handler)
# You can use restarting() to create restarting handlers easily:
with_handlers(fn(FALSE), default_empty_string = restarting("rst_null"))
}
\seealso{
\code{\link[=return_from]{return_from()}} and \code{\link[=return_to]{return_to()}} for a more flexible way
of performing a non-local jump to an arbitrary call frame.
}
\keyword{internal}
rlang/man/nse-defuse.Rd 0000644 0001762 0000144 00000021402 13604124170 014452 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nse-defuse.R
\name{nse-defuse}
\alias{nse-defuse}
\alias{quotation}
\alias{expr}
\alias{enexpr}
\alias{exprs}
\alias{enexprs}
\alias{ensym}
\alias{ensyms}
\alias{quo}
\alias{enquo}
\alias{quos}
\alias{enquos}
\title{Defuse R expressions}
\usage{
expr(expr)
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)
enquo(arg)
quos(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE
)
enquos(
...,
.named = FALSE,
.ignore_empty = c("trailing", "none", "all"),
.unquote_names = TRUE,
.homonyms = c("keep", "first", "last", "error"),
.check_assign = FALSE
)
}
\arguments{
\item{expr}{An expression.}
\item{arg}{A symbol representing an argument. The expression
supplied to that argument will be captured instead of being
evaluated.}
\item{...}{For \code{enexprs()}, \code{ensyms()} and \code{enquos()}, names of
arguments to capture without evaluation (including \code{...}). For
\code{exprs()} and \code{quos()}, the expressions to capture unevaluated
(including expressions contained in \code{...}).}
\item{.named}{Whether to ensure all dots are named. Unnamed
elements are processed with \code{\link[=quo_name]{quo_name()}} to build a default
name. See also \code{\link[=quos_auto_name]{quos_auto_name()}}.}
\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. Note that \code{"trailing"}
applies only to arguments passed in \code{...}, not to named
arguments. On the other hand, \code{"all"} also applies to named
arguments.}
\item{.unquote_names}{Whether to treat \verb{:=} as \code{=}. Unlike \code{=}, the
\verb{:=} syntax supports \verb{!!} unquoting on the LHS.}
\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 passed in
dots. When \code{TRUE} and a \verb{<-} call is detected, a warning is
issued to advise users to use \code{=} if they meant to match a
function parameter, or wrap the \verb{<-} call in braces otherwise.
This ensures assignments are explicit.}
}
\description{
\Sexpr[results=rd, stage=render]{rlang:::lifecycle("stable")}
The defusing operators \code{expr()} and \code{enquo()} prevent the
evaluation of R code. Defusing is also known as \emph{quoting}, and is
done in base R by \code{\link[=quote]{quote()}} and \code{\link[=substitute]{substitute()}}. When a function
argument is defused, R doesn't return its value like it normally
would but it returns the R expression describing how to make the
value. These defused expressions are like blueprints for computing
values.
There are two main ways to defuse expressions, to which correspond
the two functions \code{expr()} and \code{enquo()}. Whereas \code{expr()} defuses
your own expression, \code{enquo()} defuses expressions supplied as
argument by the user of a function. See section on function
arguments for more on this distinction.
The main purpose of defusing evaluation of an expression is to
enable data-masking, where an expression is evaluated in the
context of a data frame so that you can write \code{var} instead of
\code{data$var}. The expression is defused so it can be resumed later
on, in a context where the data-variables have been defined.
Defusing prevents the evaluation of R code, but you can still force
evaluation inside a defused expression with the \link[=nse-force]{forcing operators} \verb{!!} and \verb{!!!}.
}
\section{Types of defused expressions}{
\itemize{
\item \strong{Calls}, like \code{f(1, 2, 3)} or \code{1 + 1} represent the action of
calling a function to compute a new value, such as a vector.
\item \strong{Symbols}, like \code{x} or \code{df}, represent named objects. When the
object pointed to by the symbol was defined in a function or in
the global environment, we call it an environment-variable. When
the object is a column in a data frame, we call it a
data-variable.
}
You can create new call or symbol objects by using the defusing
function \code{expr()}:\preformatted{# Create a symbol representing objects called `foo`
expr(foo)
# Create a call representing the computation of the mean of `foo`
expr(mean(foo, na.rm = TRUE))
}
Defusing is not the only way to create defused expressions. You can
also assemble them from data:\preformatted{# Assemble a symbol from a string
var <- "foo"
sym(var)
# Assemble a call from strings, symbols, and other objects
call("mean", sym(var), na.rm = TRUE)
}
}
\section{Defusing function arguments}{
There are two points of view when it comes to defusing an
expression:
\itemize{
\item You can defuse expressions that \emph{you} supply with \code{expr()}. This
is one way of creating symbols and calls (see previous section).
\item You can defuse the expressions supplied by \emph{the user} of your
function with the operators starting with \code{en} like \code{ensym()},
\code{enquo()} and their plural variants. They defuse function
arguments .
}
}
\section{Defused arguments and quosures}{
If you inspect the return values of \code{expr()} and \code{enquo()}, you'll
notice that the latter doesn't return a raw expression like the
former. Instead it returns a \strong{quosure}, a wrapper containing an
expression and an environment. R needs information about the
environment to properly evaluate the argument expression because it
comes from a different context than the current function.
See the \link{quosure} help topic about tools to work with quosures.
}
\section{Comparison to base R}{
\itemize{
\item The defusing operator \code{expr()} is similar to \code{\link[=quote]{quote()}}. Like
\code{\link[=bquote]{bquote()}}, it allows \link[=nse-defuse]{forcing} evaluation of parts
of an expression.
\item The plural variant \code{exprs()} is similar to \code{\link[=alist]{alist()}}.
\item The argument-defusing operator \code{enquo()} is similar to
\code{\link[=substitute]{substitute()}}.
}
}
\examples{
# expr() and exprs() capture expressions that you supply:
expr(symbol)
exprs(several, such, symbols)
# enexpr() and enexprs() capture expressions that your user supplied:
expr_inputs <- function(arg, ...) {
user_exprs <- enexprs(arg, ...)
user_exprs
}
expr_inputs(hello)
expr_inputs(hello, bonjour, ciao)
# ensym() and ensyms() provide additional type checking to ensure
# the user calling your function has supplied bare object names:
sym_inputs <- function(...) {
user_symbols <- ensyms(...)
user_symbols
}
sym_inputs(hello, "bonjour")
## sym_inputs(say(hello)) # Error: Must supply symbols or strings
expr_inputs(say(hello))
# All these quoting functions have quasiquotation support. This
# means that you can unquote (evaluate and inline) part of the
# captured expression:
what <- sym("bonjour")
expr(say(what))
expr(say(!!what))
# This also applies to expressions supplied by the user. This is
# like an escape hatch that allows control over the captured
# expression:
expr_inputs(say(!!what), !!what)
# Finally, you can capture expressions as quosures. A quosure is an
# object that contains both the expression and its environment:
quo <- quo(letters)
quo
get_expr(quo)
get_env(quo)
# Quosures can be evaluated with eval_tidy():
eval_tidy(quo)
# They have the nice property that you can pass them around from
# context to context (that is, from function to function) and they
# still evaluate in their original environment:
multiply_expr_by_10 <- function(expr) {
# We capture the user expression and its environment:
expr <- enquo(expr)
# Then create an object that only exists in this function:
local_ten <- 10
# Now let's create a multiplication expression that (a) inlines
# the user expression as LHS (still wrapped in its quosure) and
# (b) refers to the local object in the RHS:
quo(!!expr * local_ten)
}
quo <- multiply_expr_by_10(2 + 3)
# The local parts of the quosure are printed in colour if your
# terminal is capable of displaying colours:
quo
# All the quosures in the expression evaluate in their original
# context. The local objects are looked up properly and we get the
# expected result:
eval_tidy(quo)
}
rlang/man/local_options.Rd 0000644 0001762 0000144 00000004213 13563535650 015277 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 13407134203 013571 5 ustar ligges users rlang/man/figures/lifecycle-defunct.svg 0000644 0001762 0000144 00000001704 13405732277 017716 0 ustar ligges users