My actual working directory of a .Rmd file is "C:/Users/Camilo Erasso/Documents"
. I want to change it using knitr::opts_knit$set(root.dir ="D:/CAMILO")
in the setup chunk.
This works fine whit the default YAML option: editor_options: chunk_output_type: inline
. But when I change this option to editor_options: chunk_output_type: console
the new working directory is ignored or not changed.
I'm not used to work whit inline result (I prefer the console), for that reason I use this option. The same option can be changed in RStudio>Tools>Global Options...>R Markdown>Show output inline for all R Markdown documents (uncheck)
or in the .Rmd setting buttom (next to Knit buttom)> Chunk Output in Console
Toy example:
---
title: "Example root.dir change"
author: "Camilo"
date: "2 de abril de 2019"
output: html_document
---
```{r setup, include=FALSE}
getwd() #[1] "C:/Users/Camilo Erasso/Documents"
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir ="D:/CAMILO")
```
```{r}
getwd() #[1] "D:/CAMILO"
```
But when using the console output option:
---
title: "Example root.dir change"
author: "Camilo"
date: "2 de abril de 2019"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
getwd() #[1] "C:/Users/Camilo Erasso/Documents"
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir ="D:/CAMILO")
```
```{r}
getwd() #[1] "C:/Users/Camilo Erasso/Documents" or NOT CHANGED
```
This problem is slightly different from this: https://github.com/yihui/knitr/issues/1575
And related whit this: https://github.com/rstudio/rmarkdown/issues/1077
and this https://stackoverflow.com/questions/41911487/html-notebook-ignores-global-chunk-options.
Is this and RStudio issue? Thanks for your help!!!