在 R 编程中评估和引用表达式 – bquote()函数
R 语言中的bquote()
函数用于引用传递给它的参数,但包含在 ' .() ' 中的值除外。它评估包装的值并引用结果。
Syntax: bquote(expr)
Parameters:
expr: language object
示例 1:
# R program to quote an expression
# Assigning value to variable
x <- 10
# Calling bquote() Function
bquote(x == x)
bquote(x == 10)
bquote(x == .(x))
bquote(x == .(x * 2))
输出:
x == x
x == 10
x == 10
x == 20
示例 2:
# R program to quote an expression
# Assigning value to variable
z <- 10
# Calling bquote() Function
bquote(function(x, y = .(z)) x + y)
# Plotting a graph with the default value
plot(1:10, z+(1:10), main = bquote(z == .(z)))
输出:
function(x, y = 10) x + y