eval_glue: [!] Format, parse and evaluate expression in a string

Description Usage Arguments Details See Also Examples

View source: R/eval_glue.R

Description

A wrapper function to format and parse a string and evaluate it as an expression. eval_(X) is a wrapper for eval(parse(text = glue::glue(X))).

Usage

1
eval_glue(..., envir = parent.frame(), .sep = "", .open = "{", .close = "}")

Arguments

...

Strings to be formatted and evaluated as an expression.

envir

[environment: parent.frame()]
Environment to evaluate each expression in. Expressions are evaluated from left to right. If .x is an environment, the expressions are evaluated in that environment and .envir is ignored. If NULL is passed it is equivalent to emptyenv().

.sep

[character(1): ‘""’]
Separator used to separate elements.

.open

[character(1): ‘{’]
The opening delimiter. Doubling the full delimiter escapes it.

.close

[character(1): ‘}’]
The closing delimiter. Doubling the full delimiter escapes it.

Details

It's a good practice to write backticks (') arround variable names to prevent from errors in situations, where variables have uncommon names. See examples.

See Also

Format and interpolate a string (glue).
Evaluate an (unevaluated) expression (eval).
Parse expressions (parse).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library("spMisc")

AA <- "nn"

glue::glue("{AA} <- 3")

eval_glue("{AA} <- 3")

AA

nn

 # It's a good practice to write backticks (`) arround variable names
 # to prevent from errors in situations, where variables have uncommon
 # names:

BB <- "A B"

eval_glue("`{BB}` <- 8")

`A B`

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.