I'm interested in attaching metadata to saved objects, including the script that saved the data. Towards that end, I would like to catch the name of a script in the script itself.
When I have an Rmarkdown document as below and I knit it, the code chunk results in the name of the script that generated it. This is exactly what I want, however, this only works when the document is being knit. I would like to do the same if I'm executing the chunk in Rstudio in an interactive way.
---
title: "test"
author: "me"
date: "21/09/2020"
output: html_document
---
```{r}
if (interactive()) {
# Get the same as non-interactive version?
} else {
as.character(sys.call(1))[2]
}
```
Does anybody know how to catch the name of the current Rmarkdown script in an interactive session?