Reputation: 471
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?
Upvotes: 6
Views: 1614
Reputation: 66834
Use deparse
:
x <- call("sum",1:10)
as.character(x)
[1] "sum" "1:10"
deparse(x)
[1] "sum(1:10)"
Upvotes: 9