Aliases: substitute quote enquote
Keywords: programming data
### ** Examples require(graphics) (s.e <- substitute(expression(a + b), list(a = 1))) #> expression(1 + b)
expression(1 + b)
(s.s <- substitute( a + b, list(a = 1))) #> 1 + b
1 + b
c(mode(s.e), typeof(s.e)) # "call", "language"
[1] "call" "language"
c(mode(s.s), typeof(s.s)) # (the same)
[1] "call" "language"
# but: (e.s.e <- eval(s.e)) #> expression(1 + b)
expression(1 + b)
c(mode(e.s.e), typeof(e.s.e)) # "expression", "expression"
[1] "expression" "expression"
substitute(x <- x + 1, list(x = 1)) # nonsense
1 <- 1 + 1
myplot <- function(x, y) plot(x, y, xlab = deparse1(substitute(x)), ylab = deparse1(substitute(y))) ## Simple examples about lazy evaluation, etc: f1 <- function(x, y = x) { x <- x + 1; y } s1 <- function(x, y = substitute(x)) { x <- x + 1; y } s2 <- function(x, y) { if(missing(y)) y <- substitute(x); x <- x + 1; y } a <- 10 f1(a) # 11
[1] 11
s1(a) # 11
[1] 11
s2(a) # a
a
typeof(s2(a)) # "symbol"
[1] "symbol"