Related Articles

Related Articles

Convert an Expression to a String in R Programming – deparse() Function
  • Last Updated : 24 Jun, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

[1] "expression"
[1] "character"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

[1] 8
[1] "expression(2^3)"
My Personal Notes arrow_drop_up
Recommended Articles
Page :