quoting.env: Given a list of names, build an environment such that...

Description Usage Arguments Details Value Note Author(s) Examples

Description

Technically, this defines two nested environments, the outer containing functions and the inner containing names, and returns the inner.

Usage

1
quoting.env(names, parent = emptyenv(), call.names = names)

Arguments

names

The names the environment should define.

parent

The parent environment (defaults to the empty environment)

call.names

The functions the enclosing environment should define. Decaults to names, but sometimes you want these to be different.

Details

This somewhat esoteric function mostly intended to be used by expand_macros

Value

The environment constructed.

Note

This will cause errors when the expression has missing arguments. The expression might be preprocessed (somewhow?) to take missing arguments out.

Author(s)

Peter Meilstrup

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
en <- quoting.env(c('+', '(', 'a', 'b', '*'), environment())

evalq(a+b, en) # a+b
evalq(a+(b*a), en) # a+(b*a)
z <- 100
evalq(a+(b*a)*z, en) #a+(b*a)*100

##We can build a function that does something like substitute() like this:
ersatz.substitute <- function(expr, envir=arg_env(expr)) {
  parent <- as.environment(envir)
  en <- quoting.env(setdiff(all.names(expr), ls(parent)), parent)
  eval(expr, en)
}

ersatz.substitute(quote(a+b+c), list(b=quote(q+y))) # returns a+(q+y)+c

crowding/vadr documentation built on May 14, 2019, 11:33 a.m.