I'd like to propose an extension of the native API to expose some information about context objects.
Although you could consider them to be implementation details of R, you need at least some introspection to be able to write proper IDEs.
It should be possible, e.g., to write a tool like RStudio without copy-and-paste from internal header files.
I'd like to propose something along the lines of:
typedef void *RCNTXT;
// returns a handle to the current context object
// returns the closest enclosing function context (even if, say, in the browser context) or NULL if no functions are being executed
// returns caller context of a given context or NULL if there is no caller
RCNTXT R_getParentContext(RCNTXT c);
// returns environment of a given context
SEXP R_getContextEnvironment(RCNTXT c);
// return function of a given (function) context or NULL if given context is not function context
SEXP R_getContextFunction(RCNTXT c);
// returns a call site (language object) of a given context
SEXP R_getContextCall(RCNTXT c);
// returns a source ref of a given context
SEXP R_getContextSrcRef(RCNTXT c);
// are we currently debugging via browser function?
// is this a top level context
bool R_isGlobal(RCNTXT c);
// compares two context objects
bool R_isEqual(RCNTXT x, RCNTXT y);
Do you think that makes sense?
Any reason not to expose this information?
Were there previous attempts to add such an interface that I'm not aware of?