pandoc and rmarkdown: Can't fetch an image one level above a rmarkdown document

本小妞迷上赌 提交于 2021-02-05 04:58:16

问题


I am just starting to use rmarkdown, pandoc and knitr. I am having a great deal of difficult trying to get pandoc to fetch an image that is one level above an rmarkdown document. For example, consider our project directory is ~/test, the following rmarkdown is located at ~/test/scripts:

---
title: "test"
---

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

![test](figures/test.svg)

I then run the command Rscript -e "rmarkdown::render('scripts/test.Rmd')" from the ~/test directory. And it gives me the 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 the root.dir to be the project directory, that pandoc will fetch files relative to that? But it seems that the "working directory" is always set to relative to the where the rmarkdown document is? Any help would be appreciated. Thanks,

>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`

回答1:


Pandoc does not know knitr's root.dir option. You have to write paths relative to the current working directory, e.g., ../figures/test.svg. Or run Rscript under the scripts directory.

If you just started using rmarkdown and knitr, I strongly recommend you not to use the root.dir option, unless you really understand what it means. These directories can be really, really tricky.



来源:https://stackoverflow.com/questions/27910312/pandoc-and-rmarkdown-cant-fetch-an-image-one-level-above-a-rmarkdown-document

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