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?
There are two methods to call a function from string stored in a variable. The first one is by using the window object method and the second one is by using eval() method. The eval() method is older and it is deprecated.
How to Convert Python Int to String: To convert an integer to string in Python, use the str() function. This function takes any data type and converts it into a string, including integers. Use the syntax print(str(INT)) to return the int as a str , or string.
The JavaScript call() Method The call() method is a predefined JavaScript method. It can be used to invoke (call) a method with an owner object as an argument (parameter). With call() , an object can use a method belonging to another object.
Instead of using the locals() and the globals() function to convert a string to a variable name in python, we can also use the vars() function. The vars() function, when executed in the global scope, behaves just like the globals() function.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With