get_current_document() makes a guess at what the path to the current
document is. Returns the character "console" when it can't find the
document. This is a decent proxy for finding the document this function was
run in.
get_current_document()
A character with the path to the document
When executed interactively within RStudio, it reports the currently opened document at the time of execution. If the active document is switched between queuing this function and execution, the document of origin might be misreported.
doc <- get_current_document()