简体   繁体   English

如何以编程方式获取当前文件的 Knit 目录?

[英]How to get the Knit directory of a current file programmatically?

In the current version (1.2.5001) of RStudio, there are 2 ways to set the Knit directory (working directory for R Markdown files).在RStudio的当前版本(1.2.5001)中,有2种方法可以设置Knit目录(R Markdown文件的工作目录) See Fig. 1 and Fig. 2.参见图 1 和图 2。

在此处输入图像描述

Fig. 1 The global option to set the default Knit directory in RStudio.图1 RStudio中设置默认Knit目录的全局选项。


在此处输入图像描述

Fig. 2 The way to set the Knit directory for an individual file.图 2为单个文件设置 Knit 目录的方法。


You can use the following code to retrieve the Global option from Fig. 1:您可以使用以下代码从图 1 中检索 Global 选项:

.rs.readUiPref("knit_working_dir")

The question: how can the Knit directory of an individual file (which was set in Fig. 2) be retrieved programmatically?问题:如何以编程方式检索单个文件(在图 2 中设置)的 Knit 目录?

Does this meet your needs?这是否满足您的需求?

dirname(rstudioapi::getSourceEditorContext()$path)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM