sym {rlang}R Documentation

Create a symbol or list of symbols

Description

Symbols are a kind of defused expression that represent objects in environments.

Only tidy eval APIs support the .data pronoun. With base R functions, use simple symbols created with sym() or syms().

Usage

sym(x)

syms(x)

data_sym(x)

data_syms(x)

Arguments

x

For sym() and data_sym(), a string. For syms() and data_syms(), a list of strings.

Value

For sym() and syms(), a symbol or list of symbols. For data_sym() and data_syms(), calls of the form .data$foo.

See Also

Examples

# Create a symbol
sym("cyl")

# Create a list of symbols
syms(c("cyl", "am"))

# Symbolised names refer to variables
eval(sym("cyl"), mtcars)

# Beware of scoping issues
Cyl <- "wrong"
eval(sym("Cyl"), mtcars)

# Data symbols are explicitly scoped in the data mask
try(eval_tidy(data_sym("Cyl"), mtcars))

# These can only be used with tidy eval functions
try(eval(data_sym("Cyl"), mtcars))

# The empty string returns the missing argument:
sym("")

# This way sym() and as_string() are inverse of each other:
as_string(missing_arg())
sym(as_string(missing_arg()))


[Package rlang version 1.1.4 Index]