I am using knitr for making a markdown report for some bash commands. However, my operations include changing a directory and creating a file there, so it would be ideal if I could use cd
in my .Rmd file:
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
```
However, the file myfile
is created in the directory from which I compile the document with knit
and not in mytest
. I guess a new bash shell is started for each code chunk.
I have seen discussions about setting cwd
in R (https://github.com/yihui/knitr/issues/277) but not for bash.
Is there a way of maybe setting a working directory for a code chunk?