In many (interpreted) programming languages, a variable is set when sourcing a file so that some code can determine the filename from where it is loaded. E.g. in ruby, the variable __FILE__
is set when loading a file.
Is there such a feature in R? Is there a way for R code to determine from where it is loaded?
Example:
main.R:
source("foo.R")
/home/bar/foo.R:
print(FULL_FILENAME)
What do I have to replace FULL_FILENAME with to make it print:
[1] "/home/bar/foo.R"
without hardcoding any filenames in the source?