bookdown 问题 - knitr::include_graphics() - "Unable to load picture or PDF file" 使用图片 URL

bookdown issue - knitr::include_graphics() - "Unable to load picture or PDF file" using image URL

预计到达时间:我不知道这是否有影响,但几天前,我 upgraded/updated 我的 Linux 包裹。我过去遇到过问题,导致 R/RStudio.

中出现一些问题

bookdown 发生了奇怪的事情。就在几天前,bookdown 正在漂亮地构建我的书。现在,当我尝试构建我的书时,似乎 knitr::include_graphics() 正在制造一个问题,但前提是它指向图像 URL.

我创建了一个 new bookdown 项目来查看问题是否会持续存在;它做了。 bookdown 完美地构建了 Yihui 的最小示例。然后,我使用 knitr::include_graphics() 在书的目录中添加了一个图像文件。同样,在这种情况下,bookdown 构建了这本书,并且一切正常。但是,当我将图像位置更改为 URL 时,错误消息显示为:

! LaTeX Error: File `https://upload.wikimedia.org/wikipedia/commons/2/2e/Charle s_Darwin_seated_crop' not found.

Error: Failed to compile testbook.tex. See testbook.log for more info. Execution halted

Exited with status 1.

我很茫然。我唯一要更改的是 include_graphics() 命令是使用本地文件还是 URL 中的文件。任何建议表示赞赏。这是我的会话信息:

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

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

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

other attached packages:
 [1] ggthemr_1.1.0            mapdata_2.3.0           
 [3] maps_3.3.0               BRugs_0.9-0             
 [5] bookdown_0.8.2           blogdown_0.9            
 [7] rasterImage_0.3.0        plotrix_3.7-4           
 [9] rasterVis_0.45           latticeExtra_0.6-28     
[11] lattice_0.20-38          gridExtra_2.3           
[13] rgeos_0.4-2              dismo_1.1-4             
[15] RColorBrewer_1.1-2       ggthemes_4.0.1          
[17] R2OpenBUGS_3.2-3.2       popbio_2.4.4            
[19] demogR_0.6.0             png_0.1-7               
[21] jpeg_0.1-8               rnaturalearthhires_0.1.0
[23] rnaturalearthdata_0.1.0  rnaturalearth_0.1.0     
[25] raster_2.8-4             rgdal_1.3-6             
[27] scales_1.0.0             ggmap_2.7.904           
[29] ggvis_0.4.4              rworldmap_1.3-7         
[31] maptools_0.9-4           sp_1.3-1                
[33] googlesheets_0.3.0       forcats_0.3.0           
[35] stringr_1.3.1            dplyr_0.7.8             
[37] purrr_0.2.5              readr_1.3.0             
[39] tidyr_0.8.2              tibble_1.4.2            
[41] ggplot2_3.1.0            tidyverse_1.2.1         

loaded via a namespace (and not attached):
 [1] nlme_3.1-137      bitops_1.0-6      sf_0.7-1         
 [4] lubridate_1.7.4   httr_1.4.0        tools_3.4.4      
 [7] backports_1.1.2   R6_2.3.0          spData_0.2.9.6   
[10] DBI_1.0.0         lazyeval_0.2.1    colorspace_1.3-2 
[13] withr_2.1.2       tidyselect_0.2.5  compiler_3.4.4   
[16] cli_1.0.1         rvest_0.3.2       xml2_1.2.0       
[19] hexbin_1.27.2     classInt_0.2-3    digest_0.6.18    
[22] foreign_0.8-70    rmarkdown_1.11    pkgconfig_2.0.2  
[25] htmltools_0.3.6   rlang_0.3.0.1     readxl_1.1.0     
[28] rstudioapi_0.8    shiny_1.2.0       bindr_0.1.1      
[31] generics_0.0.2    zoo_1.8-4         jsonlite_1.6     
[34] magrittr_1.5      dotCall64_1.0-0   Rcpp_1.0.0       
[37] munsell_0.5.0     yaml_2.2.0        stringi_1.2.4    
[40] plyr_1.8.4        grid_3.4.4        parallel_3.4.4   
[43] promises_1.0.1    crayon_1.3.4      haven_2.0.0      
[46] hms_0.4.2         knitr_1.21        pillar_1.3.0     
[49] boot_1.3-20       rjson_0.2.20      codetools_0.2-15 
[52] glue_1.3.0        evaluate_0.12     modelr_0.1.2     
[55] spam_2.2-0        httpuv_1.4.5      RgoogleMaps_1.4.3
[58] cellranger_1.1.0  gtable_0.2.0      assertthat_0.2.0 
[61] xfun_0.4          mime_0.6          xtable_1.8-3     
[64] broom_0.5.1       e1071_1.7-0       coda_0.19-2      
[67] later_0.7.5       class_7.3-14      viridisLite_0.3.0
[70] fields_9.6        units_0.6-2       bindrcpp_0.2.2 

假设你把

include_graphics("https://upload.wikimedia.org/wikipedia/commons/2/2e/Charles_Darwin_seated_crop.jpg")

在您的文档中,那么问题是 LaTeX 无法处理 URLs。如果你把 .jpg 关掉,那么 URL 就真的不存在了。

您需要下载文件并引用本地副本。