RockScience RockScience - 1 year ago 69
R Question

coerce a function call into a string

I am trying to understand what is a

object in R and to coerce it to characters. However my efforts have been vain so far.

> myFun=function(a=1) { return(as.character(x)) }
> x=myFun(a=2)
> print(x) # 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
). But I couldn't find it.

Does anybody here knows how call objects are printed?

Answer Source

We can use with deparse

myFun <- function(a=1) { 

#[1] "myFun(a = 2)"

Or replace with in the function

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download