我刚开始使用rmarkdown,pandoc和knitr。我有很大的困难,试图让pandoc获取比rmarkdown文档高一级的图像。例如,考虑我们的项目目录〜/测试,下面rmarkdown位于〜/测试/脚本:pandoc和rmarkdown:无法获取高于rmarkdown文档一级的图像
---
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')"
。它给我的错误:
pandoc: Could not fetch figures/test.svg
figures/test.svg: openBinaryFile: does not exist (No such file or directory)
我会通过设置root.dir是项目目录有想到,这pandoc相对于该文件将获取?但似乎“工作目录”总是设置为相对于rmarkdown文档的位置?任何帮助,将不胜感激。谢谢,
>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`
如果您从'scripts'目录内运行脚本,它会工作吗? –
不幸的是没有。当我运行时,cd〜/ test/scripts && Rscript -e“rmarkdown :: render('scripts/test.Rmd')”我得到同样的错误。 – TinyHeero
我认为你应该从'脚本'里面运行'scripts/test.Rmd'到'test.Rmd' –