Convert an Expression to a String in R Programming – deparse() Function
deparse() function in R Language is used to convert an object of expression class to an object of character class.
Syntax: deparse(expr)
Parameters:
expr: Object of expression class
Example 1:
# R program to convert # expression to character # Creating an object of expression classx <- expression(sin(pi / 2)) # Class of objectclass(x) # Calling deparse() Functionx1 <- deparse(x) # Class of parsed objectclass(x1) |
Output:
[1] "expression" [1] "character"
Example 2:
# R program to convert # expression to character # Creating an object of expression classx <- expression(2 ^ 3) # Evaluating the value of objecteval(x) # Calling deparse() Functionx1 <- deparse(x) # Evaluating the value of objecteval(x1) |
Output:
[1] 8 [1] "expression(2^3)"


