Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need the filename of the Rmd when knitr runs

Recently I asked about having an r variable set to the name of an Rmd file when knitr runs.

Need the filename of the Rnw when knitr runs in rStudio

knitr:::.knitEnv$input.dir
knitr:::knit_concord$get("infile")

Is there a similar knitr::: object for the name of an Rmd file?

like image 601
Kate Avatar asked Jan 13 '14 21:01

Kate


2 Answers

knitr::current_input() will return the name of the Rmd file

like image 75
Andy Lyons Avatar answered Sep 28 '22 00:09

Andy Lyons


You can search through the parent.frames until you find the frame referring to where the body of the function knitr is being evaluated (and thus the input argument is defined.

get(env = parent.frame(n = 8), 'input')

Works for me.

Note that I have not tested what happens if input is not a file name.....

like image 29
mnel Avatar answered Sep 27 '22 23:09

mnel