Could not find image while rendering pdf in R markdown - r

I am trying to render a pdf file using R markdown. I want to embed an image on the page and using the following syntax:
image: ![](logo.png)
While creating the pdf, I get an error saying
`pandoc.exe: Could not find image logo.png, skipping...
pandoc.exe: Error producing PDF from TeX source.
! Package pdftex.def Error: File logo.png not found.`
Error: pandoc document conversion failed with error 43
The image exists, and don't know why it is failing. I even gave the exact path with drive and folder names, but still fails.
My File is simple as:
---
title: 'Test'
author: "Foo"
date: "Wednesday, December 17, 2014"
output: pdf_document
---
```{r}
summary(cars)
```
image: ![](logo.png)

Related

Very simple .rmd --> beamer_presentation; still cannot get rid of "Option clash for package xcolor"

I cannot compile to a pdf-beamer from a very simple minimal example (below), with no packages.
I click - Knit - Knit to pdf
(Note this is not a duplicate of previous posts, because those all involved using Kable; I am not using it; fresh restart not calling any packages here)
I tried with and without classoption: table
Knit to html works just fine.
Restarted Rstudio; no improvement
---
title: "Untitled"
author: "Test"
date: "20 novembre 2018"
classoption: table
output:
beamer_presentation:
keep_tex: yes
---
# Test nothing
blah
```
Throws error: ! LaTeX Error: Option clash for package xcolor.
I want it to compile a beamer pdf slide show, of course.
I've put the log file here
My default.beamer (stored at /Users/yosemite/.pandoc/templates/default.beamer I think) is linked HERE

RMarkdown: ! Package pdftex.def Error; online image not found?

I am running into a problem when trying to include a web-based image within a R Markdown PDF document.
Minimal Example:
---
title: "Random"
output: pdf_document
---
![Benjamin Bannekat](https://octodex.github.com/images/bannekat.png)
Knitting the above results in the error:
! 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)
The same code works fine when output is HTML.
How can I make the image show up in a PDF document?
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")
```
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.

Knitr HTML preview fails in RStudio, though render() successfully creates HTML file

I'm getting started with rmarkdown and knitr. In the sample document provided by RStudio, I can successfully use render() to generate an HTML file that views fine in Chrome. However, when I click on the knit button, it generates a .markdown file and then returns the following error without rendering the preview:
Error generating HTML preview for ~/path/to/file/report.rmarkdown system error 2 (The system cannot find the file specified)
I think it's getting hung up at the pandoc stage. Is it possible that RStudio is looking for pandoc in the wrong place? Pandoc was already installed at C:\Program Files (x86)\Pandoc\pandoc.exe, but RStudio installed its own instance at C:\Program Files\RStudio\bin\pandoc\pandoc.exe, so maybe it's looking in the wrong place and/or confusing settings from one with the other?
Any help would be greatly appreciated. Thanks!
And just in case, here's the RMarkdown template I'm starting with:
---
title: "Monthly Report"
author: "Kris Shaffer"
date: "February 17, 2017"
output: html_document
---
```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
R version 3.3.2
RStudio 1.0.136
rmarkdown 1.3
knitr 1.15.1
pandoc 1.17.2 (both installations)
Turns out it was as simple as a file extension. I changed the filename from report.rmarkdown to report.Rmd. Knit works fine now.

Using knit2pdf with Rmd files

Is it possible to use the knitr function knit2pdf() directly with R Markdown (Rmd) files? I've seen various tutorials/class notes that seem to suggest it can e.g. here and here (Ctrl+F "knit2pdf" in either).
But when I take a simple rmd file (saved as "test.rmd")
---
title: "knit2pdf test"
author: "A Aaronson"
date: "Thursday, February 19, 2015"
output: pdf_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
and try
library(knitr)
knit2pdf("test.Rmd")
I get the following error
results in:
output file: test.md
Error: running 'texi2dvi' on 'test.md' failed
LaTeX errors:
! Emergency stop
*** (job aborted, no legal \end found)
! ==> Fatal error occurred, no output PDF file produced!
! ==> Fatal error occurred, no output PDF file produced!
In addition: Warning message:
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "test.md" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Clicking the "Knit PDF" button always successfully generates a pdf. So am I missing an intermediate step?
I should add that knit2pdf() with Rnw files is working as expected for me, though I do still get the warning
running command '"C:\PROGRA~2\MIKTEX~1.9\miktex\bin\texi2dvi.exe" --quiet --pdf "rnwtest.tex" --max-iterations=20 -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/tex/latex" -I "C:/PROGRA~1/R/R-31~1.2/share/texmf/bibtex/bst"' had status 1
Help greatly appreciated.
Your input file is in rmarkdown format.
You should use the render() function in the rmarkdown package to compile your document.
Try:
library("rmarkdown")
render("temp.rmd")

R markdown error: can't produce HTML file

I can't produce an HTML document from any .Rmd file by pressing the Knit HTML button in R Studio, including the sample document that summarizes and plots the cars dataset. Here's the error message that I get:
Error: unrecognized fields specified in html_dependency: attachment
Execution halted
However, I can produce the HTML document by running the command knit2html("file.Rmd"). The Knit PDF button also functions properly. Does anyone have an idea about how to fix this error?
Here's the sample .Rmd file that I have:
title: "Untitled"
author: "blakeoft"
date: "Friday, September 12, 2014"
output: html_document
---
A summary:
```{r}
summary(cars)
```
I had the same problem which went away after upgrading to RStudio version 0.98.1056 (released 9 September 2014).
As I've answered on another thread, updating RStudio didn't work for me. So I tried updating all R packages (Tools > Check for Package Updates...) and then it worked.

Resources