Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

op-definition

Definition operator


Description

The definition operator is typically used in DSL packages like ggvis and data.table. It is also used in the tidyverse as a way of unquoting names (see nse-force).

  • is_definition() returns TRUE for calls to :=.

  • is_formulaish() returns TRUE for both formulas and colon-equals operators.

Usage

is_definition(x)

new_definition(lhs, rhs, env = caller_env())

is_formulaish(x, scoped = NULL, lhs = NULL)

Arguments

x

An object to test.

lhs, rhs

Expressions for the LHS and RHS of the definition.

env

The evaluation environment bundled with the definition.

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 := symbol in an overscope. Note that if you capture dots with exprs() or quos(), you need to disable interpretation of := by setting .unquote_names to 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.

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))

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.