.Rmd文件的实际工作目录为"C:/Users/Camilo Erasso/Documents"
。我想在设置块中使用knitr::opts_knit$set(root.dir ="D:/CAMILO")
进行更改。
使用默认的YAML选项editor_options: chunk_output_type: inline
可以正常工作。但是,当我将此选项更改为editor_options:
chunk_output_type: console
时,新的工作目录将被忽略或未更改。
我不习惯处理内联结果(我更喜欢控制台),因此我使用此选项。可以在RStudio>Tools>Global Options...>R Markdown>Show output inline for all R Markdown documents (uncheck)
或.Rmd setting buttom (next to Knit buttom)> Chunk Output in Console
玩具示例:
---
title: "Example root.dir change"
author: "Camilo Erasso"
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"
```
但是在使用控制台输出选项时:
---
title: "Example root.dir change"
author: "Camilo Erasso"
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
```
此问题与此稍有不同:https://github.com/yihui/knitr/issues/1575
与此相关的事:https://github.com/rstudio/rmarkdown/issues/1077 还有这个html_notebook ignores global chunk options。
这是RStudio的问题吗?谢谢您的帮助!!!