在r-markdown中无法从URL找到图像文件 [英] image file not found from URL in r-markdown

查看:106
本文介绍了在r-markdown中无法从URL找到图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经能够使用具有以下代码![](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark)的URL在r-markdown中渲染图像,但出现文件未找到错误! LaTeX Error: File https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark' not found. 我会丢失包裹吗?该代码仍可在几个月前发布的一些出色应用上使用.

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.

工作文件r-markdown文件下面:

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)

推荐答案

LaTeX graphicx 软件包不包含http客户端,因此无法从互联网提取图像.但是,从Markdown到LaTeX的许多转换工作是由pandoc执行的,可以获取此图像.只需通过传递--extract-media选项告诉pandoc将所有图像存储在本地即可.当RMarkdown调用LaTeX时,它可以查找图像.

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", "."]
---

以上内容将所有图像与Rmd文件存储在同一目录中.这些文件将使用SHA1哈希命名,因此您可能想为这些文件使用单独的目录.

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.

这篇关于在r-markdown中无法从URL找到图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆