5

I am trying to understand what is a call object in R and to coerce it to characters. However my efforts have been vain so far.

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 have also been looking for the function that prints a function call (something like print.call). But I couldn't find it.

Does anybody here knows how call objects are printed?

RockScience
  • 17,932
  • 26
  • 89
  • 125

1 Answers1

5

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 the function

akrun
  • 874,273
  • 37
  • 540
  • 662