Need the filename of the Rmd when knitr runs

浪尽此生 提交于 2019-12-10 20:34:05

问题


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?


回答1:


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.....




回答2:


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



来源:https://stackoverflow.com/questions/21101573/need-the-filename-of-the-rmd-when-knitr-runs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!