Search code examples
rknitrbookdown

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


ETA: I don't know if this makes a difference, but a couple days ago, I upgraded/updated my Linux packages. I have had issues in the past where that causes some issues in R/RStudio.

Strange happenings with bookdown. Just a couple days ago, bookdown was building my book beautifully. Now, when I try to build my book, it seems that knitr::include_graphics() is creating an issue, but only if it points to an image URL.

I created a new bookdown project to see if the problem would persist; it did. bookdown built Yihui's minimal example perfectly. Then, I used knitr::include_graphics() to add an image file in the book's directory. Again, in that case, bookdown built the book, and everything worked just right. But, when I changed the image location to a URL, the error message reads:

! 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.

I am at a loss. The only thing I'm changing is whether the include_graphics() command is using a local file versus one at a URL. Any suggestions are appreciated. Here is my session info:

> 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 

Solution

  • Assuming you put

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

    in your document, then the issue is that LaTeX can't handle URLs. If you left the .jpg off, then that URL really doesn't exist.

    You need to download the file and reference the local copy.