image file not found from URL in r-markdown

拈花ヽ惹草 提交于 2020-01-23 21:57:08

问题


I used to be able to render images in r-markdown using a URL with the following code ![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark) but I get a file not found error ! LaTeX Error: File https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark' not found. Am I missing packages? This code still works on some shiny apps published a few month ago.

Below the a working file r-markdown file:

---
title: "Test"
header-includes:
    - \usepackage{graphicx}
output:
  pdf_document:
    latex_engine: xelatex
    number_sections: yes
    keep_tex: yes
classoption: article
papersize: A4
fontsize: 10pt
geometry: margin=0.9in
linestretch: 1.15
---
## R Markdown
![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark)

回答1:


The LaTeX graphicx package does not include an http client, it is therefore not able to pull the image from the internet. However, a lot of the conversion work from Markdown to LaTeX is performed by pandoc, which can get this image. One just needs to tell pandoc to store all images locally by passing the --extract-media option. This allows LaTeX to find the images when it is invoked by RMarkdown.

---
output:
  pdf_document:
    pandoc_args: ["--extract-media", "."]
---

The above will store all images in the same directory as the Rmd file. The files will be named using SHA1 hashes, so you might want to use a separate directory for these files instead.



来源:https://stackoverflow.com/questions/52558238/image-file-not-found-from-url-in-r-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!