【发布时间】:2015-07-31 08:22:00
【问题描述】:
我正在使用 knitr 为一些 bash 命令制作降价报告。但是,我的操作包括更改目录并在那里创建文件,因此如果我可以在 .Rmd 文件中使用 cd 将是理想的:
make a directory
```{r mkdir, engine='bash'}
mkdir mytest
```
cd into directory
```{r cd, engine='bash'}
cd mytest
```
create file
```{r create, engine='bash'}
touch myfile
```
check contents
```{r ls, engine='bash'}
ls
```
但是,文件myfile 是在我使用knit 编译文档的目录中创建的,而不是在mytest 中创建的。我猜每个代码块都会启动一个新的 bash shell。
我看到了关于在 R (https://github.com/yihui/knitr/issues/277) 中设置 cwd 但不是为 bash 设置的讨论。
有没有办法为代码块设置工作目录?
【问题讨论】:
-
你看
opts_knit$set(root.dir = "...")和setwd("...")了吗? -
是的,但是这些都是 R 函数,我的代码块中没有任何 R 代码。我只使用 R 来调用
knit。所以我看不到在块之间更改 cwd 的可能性...... -
这是一个已知问题。请参阅yihui.name/knitr/demo/engines 的最后一段,另请参阅github.com/yihui/runr 我不太确定runr 在
bash引擎方面是否仍然可以正常工作。 -
谢谢!我去看看runr