I have a requirement to output a time stamped log of APIs in real time. These have to be output on the R console.
I wrote this function as I read a SO question here to be called from inside the API end point function. But this outputs the function name "print_log" itself. And when I replace -1 with -2, I get the full code of the calling function but without the name of the function. All I need is the function name that calls print_log.
print_log<-function(){
api<-deparse(sys.calls()[[sys.nframe()-1]])
sprintf("%20s:%40s",now(),api)
}