Are there any equivalent of C/C++ __FILE__ and __LINE__ macros in R?

486 views Asked by At

I'm trying to get the equivalent of FILE or LINE macros in C or C++ in R (or S+). Any ideas?

FILE The presumed name of the current source file (a character string literal).

LINE The presumed line number (within the current source file) of the current source line (an integer constant).

As for context - I have log messages being flushed to console from different sections of the code, and given that the messages themselves are built at run-time, it is often very difficult to find out where this log message is coming from (with the size of the R code growing to many thousand lines and running on a distributed grid). However if I could dump the FILE and LINE number along with the log messages, it would be much easier to trace the logs...

1

There are 1 answers

2
hadley On

Use the #line directive. The structure is #line nn "filename". See Duncan's Murdoch's article on source references for more.