In RStudio/RMarkdown, how to setwd?

a 夏天 提交于 2019-11-27 19:39:44
mnel

See Issue #277 and for further background, the package author's comments here

What you are looking for is the root.dir chunk option.

The following will set the root directory for this (and subsequent) code chunks

```{r setup}
opts_chunk$set(root.dir = '/tmp')
```

EDIT: RStudio 1.0.44

as of RStudio's latest release (Oct/Nov 2016), the following snippet is needed for knitr's render default:

```{r setup}
knitr::opts_knit$set(root.dir = '/tmp')
```

see Etienne's comment about versions below.

I followed the entire discussion, yet on my version...


platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 6.0
year 2019
month 04
day 26
svn rev 76424
language R
version.string R version 3.6.0 (2019-04-26) nickname Planting of a Tree


#title of the chunk: "setup"
rm(list=ls())
yourdirectory<-"F:/CasaUfficio" #here you plug in yours
require(knitr)
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = yourdirectory)

...it doesn't seem to work. in facts

mydir<-getwd()
print(mydir)

returns

[1] "C:/Users/Vimercati"

which is like it didn't change the root at all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!