I use Quarto to generate docx files. I like to include a section at the end of the qmd file that contains useful information (the Quarto version, the R version, the date and time of rendering, machine information). This information is useful later when I need to revisit the job. When I previously used RMarkdown, I was also able to extract the name of the Rmd file that was being processed, using a trick from someone (and I don't remember where...), like this (in the Rmd file itself):
This RMarkdown document has the filename r gsub(",.*$","",gsub("rmarkdown::render(","",commandArgs()[6],fixed=TRUE)).
For Quarto, the same trick does not work. Does anyone know any way to find out the name of the qmd file that is being rendered?
The quarto package can give some useful information, but not the rendering file.
I don't think we have the information stored and available from within Quarto - Maybe we could make this available in Variables system (Quarto – Variables)
The idea is tracked in
There is a Lua workaround there.
For current workaround, I am thinking of two thinks R specific
knitr has knitr::current_input() function. This will return the filename of the input being knitted. You won't get the original filename because it gets processed by Quarto and an intermediate file is passed to knitr but it is just a matter for extension so this would give you the filename
This is written in test2.qmd
---
format: html
---
The input `.qmd` file for this output is `` `r xfun::with_ext(knitr::current_input(), "qmd")` ``
It returns this
Using quarto::quarto_render() and leveraging parameters
test.qmd document
---
format: html
params:
input_file: ""
---
The input `.qmd` file for this output is `` `r params$input_file` ``
The knitr::current_input() solution works quite well, and seems to be the simplest approach for these purposes, assuming the input file has a qmd extension, which is nearly (mostly) always the case. The other solutions also look very useful, possibly for other purposes too.