Short: When inside an R library, how do you get the path of the original file calling the library?
Long: I am building a library for creating ggplots according to my organization's style. Currently, to apply the style one just needs to add + mypackage::addstyle
to the code for a plot. These plots later end up on slides, and we often forget where we put the script that made it. In order to aid in reproducible research, I would like to add a caption to each figure that states where the plot came from. E.g. W:/Important Project/script27.R
There are multiple ways to get the path of the script inside of the script. For example, rstudioapi::getActiveDocumentContext()$path
. However, when I embed those commands inside I get the library I get W:/mypackage/R/style.R
, not W:/Important Project/script27.R
.