RMarkdown :!软件包pdftex.def错误;找不到在线图片? [英] RMarkdown: ! Package pdftex.def Error; online image not found?

查看:404
本文介绍了RMarkdown :!软件包pdftex.def错误;找不到在线图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在R Markdown PDF文档中包含基于Web的图像时遇到问题.

I am running into a problem when trying to include a web-based image within a R Markdown PDF document.

最小示例:

---
title: "Random"
output: pdf_document
---

![Benjamin Bannekat](https://octodex.github.com/images/bannekat.png)

编织以上内容会导致错误:

Knitting the above results in the error:

!软件包pdftex.def错误:文件` https://octodex.github.com/images/bannekat. pn 找不到g.

! Package pdftex.def Error: File `https://octodex.github.com/images/bannekat.pn g' not found.

但是,如果我使用以下代码,则会显示该图像:

However, if I use the following code, the image shows up:

---
title: "Random"
output:
  html_document: default
  html_notebook: default
---

![Benjamin Bannekat](https://octodex.github.com/images/bannekat.png)

当输出为HTML时,相同的代码也可以正常工作.

The same code works fine when output is HTML.

如何使图像显示在PDF文档中?

How can I make the image show up in a PDF document?

推荐答案

如果要编织为PDF,则该文件必须通过LaTeX运行. LaTeX没有内置功能来显示网络上托管的文件,如突出显示的.

If you are knitting to PDF, the file has to run through LaTeX. LaTeX has no built-in capacity to display files hosted on the web, as highlighted in this question.

最好的解决方法是将网络图像下载到本地目录,然后将其指定为文件路径.

The best workaround for this is to download the web image to your local directory, and then specify this as a file path.

以下代码使用

The following code downloads the image using the download.file function, and then displays in using include_graphics. The benefit of include graphics is that it allows you to specify the width of the image in the output document, which I set to 40 pixels.

---
title: "Random"
output: pdf_document
---


```{r results = 'asis', out.width="40px"}
download.file(url = "https://octodex.github.com/images/bannekat.png",
          destfile = "image.png",
          mode = 'wb')
knitr::include_graphics(path = "image.png")
```

找出更多为什么应使用include_graphics在R Markdown文档中包括图形的原因.在此处查看我的其他答案以了解更多详细信息.

Find out more reasons why include_graphics should be used to include graphics in R Markdown documents. Check out my other answer here for more details why.

这篇关于RMarkdown :!软件包pdftex.def错误;找不到在线图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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