首页 > 解决方案 > R blogdown 找不到图像文件

问题描述

我有(有)一个用 blogdown 制作的工作网站。几个月来我第一次尝试重建该站点,但我遇到了错误,因为它显然找不到我的图像。

为了制作一个reprex,我创建了一个新项目,并选择了“带有 blogdown 的网站”选项并采用了所有默认值。该网站的构建没有 blogdown:::serve_site() 的问题。我将一个名为 x.png 的图像放入静态目录并添加:

```{r x, fig.cap='x', tidy=FALSE}
knitr::include_graphics("x.png")
```

进入 2015-07-23-r-rmarkdown.Rmd 文件。当我告诉它 blogdown:::serve_site() 我得到:

Error in knitr::include_graphics("x.png") : 
  Cannot find the file(s): "x.png"
Calls: local ... withCallingHandlers -> withVisible -> eval -> eval -> <Anonymous>
Execution halted

然后我尝试使用“插件”菜单添加图像并选择Insert Image并将其指向文件。它制作了该文件的副本并将预期的降价写入 2015-07-23-r-rmarkdown.Rmd:

![](/post/2015-07-23-r-rmarkdown_files/x.png)

这引发了这个错误:

pandoc: /post/2015-07-23-r-rmarkdown_files/x.png: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1
Execution halted

关于到底是什么问题的任何想法?

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.3

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3           later_1.0.0          compiler_3.6.2       pillar_1.4.3        
 [5] prettyunits_1.1.1    tools_3.6.2          digest_0.6.25        packrat_0.5.0-25    
 [9] pkgbuild_1.0.6       jsonlite_1.6.1       evaluate_0.14        lifecycle_0.2.0     
[13] tibble_2.1.3         gtable_0.3.0         pkgconfig_2.0.3      rlang_0.4.5         
[17] cli_2.0.2            rstudioapi_0.11      parallel_3.6.2       yaml_2.2.1          
[21] blogdown_0.18        xfun_0.12            loo_2.2.0            gridExtra_2.3       
[25] stringr_1.4.0        dplyr_0.8.4          knitr_1.28           tidyselect_1.0.0    
[29] stats4_3.6.2         grid_3.6.2           glue_1.3.1           inline_0.3.15       
[33] R6_2.4.1             processx_3.4.2       fansi_0.4.1          rmarkdown_2.1       
[37] bookdown_0.18        rstan_2.19.3         servr_0.16           purrr_0.3.3         
[41] magrittr_1.5         callr_3.4.2          ggplot2_3.3.0        promises_1.1.0      
[45] matrixStats_0.55.0   scales_1.1.0         ps_1.3.2             StanHeaders_2.21.0-1
[49] htmltools_0.4.0      rsconnect_0.8.16     assertthat_0.2.1     mime_0.9            
[53] colorspace_1.4-1     httpuv_1.5.2         stringi_1.4.6        munsell_0.5.0       
[57] crayon_1.3.4  
> rmarkdown::pandoc_version()
[1] ‘2.7.3’

标签: rblogdown

解决方案


使用插件的第二种方法:你不应该编织这个 RMD 文件。如果您只使用插件“服务站点”,它会按预期工作。当然,如果您编织它,它将不起作用,因为文件被复制到“static/post/....”并且您的 RMD 文件位于“content/post/...”中


推荐阅读