Need the filename of the Rnw when knitr runs in rS

2019-02-22 14:15发布

When working on a reproducible research project, I would like to know the name of the Rnw file that is being run to use as an R variable.

This would be analogous to inserting an MSExcel filename in a footer

I am using RStudio Server on Ubuntu.

Thank you.

2条回答
唯我独甜
2楼-- · 2019-02-22 14:44

You can use the following two idioms to fetch the directory and name of the current file in knitr:

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

This is independent of RStudio, the knitr package is entirely responsible for this. These are private functions and variables that can change at any time without notice, so if you need something reliable, you might want to file an issue on GitHub.

查看更多
Anthone
3楼-- · 2019-02-22 14:46

knitr now has a method for this: current_input()

https://github.com/yihui/knitr/issues/701

查看更多
登录 后发表回答