# Can't add images to R Markdown file

#1

When trying to add an image using ![Caption for the picture.](screenshot.png), I get the error:

pandoc.exe: Could not fetch screenshot.png
screenshot.png: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 67
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS README.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output README.html --smart --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\safety\Documents\R\win-library\3.4\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\safety\AppData\Local\Temp\RtmpiQHMmI\rmarkdown-strd4838453ffe.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"' had status 67
Execution halted

The image file is in the same directory as the rmd file so I don't know what could be the problem.

#2

I don't seem to have this problem.

If I use the following:

---
title: "Example"
output: pdf_document
---

some text

![caption](picture.jpg)

some text


, it generates pdf version - unwanted location of picture.pdf (388.4 KB).

However, because of the change in location, I will prefer the following:

---
title: "Example"
output: pdf_document
- \usepackage{caption}
---

some text

\includegraphics{picture.jpg}
\captionof{figure}{caption}

some text


This will generate pdf version - picture located in expected position.pdf (387.7 KB).

If you want to use ![caption](picture_name.extension), use HTML.

---
title: "Example"
output: html_document
---

some text

![caption](picture.jpg)

some text


This yields

.

Hope this helps.

#3

I made the post because I'm getting an error if I try it that way. It says it can't find the file when I try to knit.

#4

I fixed the issue. I somehow saved the screenshot as screenshot.png.png

#5

I think it would help a lot if you could provide a small reproducible example of this problem. In this case, here's how I'd go about doing that:

1. Make a new RStudio Project in a new directory
2. Add a sample image to the new Project directory.
3. Create a new, minimal RMarkdown document that includes the sample image.
4. See if the problem occurs when you try to knit this new RMarkdown document. (if not, that at least helps narrow things down!)

If the problem does occur, then definitely post the contents of your new sample Rmd, and also the output of running the following three commands from the console in your new RStudio Project:

list.files()
sessionInfo()
system("pandoc --version")


At the same time, you might try seeing if your original file will knit if you set self_contained: false in the YAML header. This doesn't solve the problem if you want self-contained HTML output, but it might be a workaround.