Pandoc and rmarkdown: unable to get image one level above rmarkdown document

I am just getting started with rmarkdown, pandoc and knitr. I am having a lot of difficulty trying to get pandoc to get an image that is flush above the rmarkdown document. For example, consider that our project directory is ~ / test, the following rmarkdown is in ~ / test / scripts:

---
title: "test"
---

```{r global_options, include=FALSE}
library('knitr')
opts_knit$set(root.dir = '~/test')
```

![test](figures/test.svg)

      

Then I run the command Rscript -e "rmarkdown::render('scripts/test.Rmd')"

from the ~ / test directory. And it gives me an error:

pandoc: Could not fetch figures/test.svg
figures/test.svg: openBinaryFile: does not exist (No such file or directory)

      

I would have thought, by setting root.dir to the project directory, which pandoc will fetch files about this? But it seems like the "working directory" is always set relative to where the rmarkdown document is located? Any help would be greatly appreciated. Thank,

>sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] vimcom_1.0-0   setwidth_1.0-3 colorout_1.0-2

loaded via a namespace (and not attached):
[1] tools_3.1.0`

      

+3


source to share


1 answer


Pandoc doesn't know the knitr option root.dir

. You must write paths relative to the current working directory, eg ../figures/test.svg

. Or run Rscript

in a directory scripts

.



If you are new to using rmarkdown and knitr , I highly recommend that you do not use the parameter root.dir

unless you understand what it means. These directories can be really, really complicated .

+2


source







All Articles