Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning a language object into a String in R

Tags:

string

r

I am writing some code in R to handle errors/warnings.

The condition object i get back is a list of a message as string and a call object, representing the function call, that caused the error. I want to have a string that is the same as if i simply used print() on the call object. However using as.character() or paste() gives back a vector of multiple strings representing the function name and parameters.

Is there an easy way to do this or do i have to build the string myself?

like image 313
Siniyas Avatar asked Mar 20 '23 02:03

Siniyas


1 Answers

Use deparse:

x <- call("sum",1:10)
as.character(x)
[1] "sum"  "1:10"
deparse(x)
[1] "sum(1:10)"
like image 89
James Avatar answered Mar 21 '23 16:03

James