My R project is structured like a package with directories /R, /vignettes, /data etc. In one of my Rmd docs in /vignettes
Some details on implementation of setting work directory by root.dir =.
Although there already are some awesome answers by Yihui and Tommy. I still got stuck in setting work directory. So I am trying to make a complete answer here.
Knitr’s settings must be set in a chunk before any chunks which rely on those settings to be active. It is recommended to create a knit configuration chunk as the first chunk in a script with cache = FALSE and include = FALSE options set. This chunk must not contain any commands which expect the settings in the configuration chunk to be in effect at the time of execution.
In my case, the .Rproj and .Rmd files are located in the same folder.
```{r setup, include=FALSE, cache = FALSE}
require("knitr")
## setting working directory
opts_knit$set(root.dir = "~/Documents/R/Example")
```