检查对象是否是 R 编程中的表达式 - is.expression()函数
R 语言中的is.expression()
函数用于检查作为参数传递给它的对象是否属于表达式类。
Syntax: is.expression(object)
Parameters:
object: Object to be checked
示例 1:
# R program to check if
# an object is an expression
# Creating an object
x <- "sin(pi / 2)"
# Printing value of the object
eval(x)
# Calling is.expression() function
is.expression(x)
输出:
[1] "sin(pi/2)"
[1] FALSE
示例 2:
# R program to check if
# an object is an expression
# Creating an object
x <- expression(sin(pi / 2))
# Printing value of the object
eval(x)
# Calling is.expression() function
is.expression(x)
输出:
[1] 1
[1] TRUE