Forcing a function call to a string

I am trying to figure out what the call object in R is and force it to characters. However, so far my efforts have been in vain.

 myFun=function(a=1) { x=sys.call() return(as.character(x)) } x=myFun(a=2) # here I would like to get the string "myFun(a = 2)" 

I was also looking for a function that prints a function call (something like print.call ). But I could not find him.

Does anyone know how call objects are printed?

+5
source share
1 answer

We can use match.call() with deparse

 myFun <- function(a=1) { deparse(match.call()) } myFun(a=2) #[1] "myFun(a = 2)" 

Or replace match.call() with sys.call() in a function

+5
source

All Articles