问题描述
在进行可重复的研究项目时,我想知道正在运行用作R变量的Rnw文件的名称.
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.
这类似于在页脚中插入MSExcel文件名
This would be analogous to inserting an MSExcel filename in a footer
我正在Ubuntu上使用RStudio服务器.
I am using RStudio Server on Ubuntu.
谢谢.
推荐答案
您可以使用以下两个习惯用法在knitr
中获取当前文件的目录和名称:
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")
这独立于RStudio,knitr
包对此完全负责.这些是私有函数和变量,可以随时更改而无需另行通知,因此,如果您需要可靠的东西,则可能需要在GitHub上提交问题.
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.
这篇关于当knitr在rStudio中运行时,需要Rnw的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!