在 R 编程中将表达式转换为字符串 - deparse()函数
R 语言中的deparse()
函数用于将表达式类的对象转换为字符类的对象。
Syntax: deparse(expr)
Parameters:
expr: Object of expression class
示例 1:
# R program to convert
# expression to character
# Creating an object of expression class
x <- expression(sin(pi / 2))
# Class of object
class(x)
# Calling deparse() Function
x1 <- deparse(x)
# Class of parsed object
class(x1)
输出:
[1] "expression"
[1] "character"
示例 2:
# R program to convert
# expression to character
# Creating an object of expression class
x <- expression(2 ^ 3)
# Evaluating the value of object
eval(x)
# Calling deparse() Function
x1 <- deparse(x)
# Evaluating the value of object
eval(x1)
输出:
[1] 8
[1] "expression(2^3)"