当knitr在rStudio中运行时,需要Rnw的文件名 [英] Need the filename of the Rnw when knitr runs in rStudio

查看:263
本文介绍了当knitr在rStudio中运行时,需要Rnw的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行可重复的研究项目时,我想知道正在运行用作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包对此完全负责.这些是私有函数和变量,可以随时更改而无需另行通知,因此,如果您需要可靠的东西,则可能需要

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的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆