pandoc和rmarkdown:无法在rmarkdown文档上一级获取图像 [英] pandoc and rmarkdown: Can't fetch an image one level above a rmarkdown document

查看:99
本文介绍了pandoc和rmarkdown:无法在rmarkdown文档上一级获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用rmarkdown,pandoc和knitr.我在尝试使pandoc获取比rmarkdown文档高一级的图像方面遇到了很多困难.例如,假设我们的项目目录为〜/test,以下rmarkdown位于〜/test/scripts:

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)

然后我从〜/test目录运行命令Rscript -e "rmarkdown::render('scripts/test.Rmd')".它给了我错误:

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)

我会认为通过将root.dir设置为项目目录,pandoc将获取与此相对的文件?但是似乎工作目录"始终设置为相对于rmarkdown文档所在的位置?任何帮助,将不胜感激.谢谢,

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`

推荐答案

Pandoc不知道 knitr root.dir选项.您必须编写相对于当前工作目录的路径,例如../figures/test.svg.或在scripts目录下运行Rscript.

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.

如果您刚开始使用 rmarkdown knitr ,强烈建议您不要使用root.dir选项,除非您真的了解它的含义.这些目录可以是真的,真的很棘手.

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.

这篇关于pandoc和rmarkdown:无法在rmarkdown文档上一级获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆