Can't add images to R Markdown file

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
In addition: Warning message:
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.

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.

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

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.

Hello colleagues
I am facing a similar issue. But my error message is different. My image file is located in the same directory as the markdown file.

Please see the screenshot. The code I am writing is

![Districts](Chicago_Districts.png<U+2069>)

And here is the error message;

Error: unexpected '[' in "!["

Can I kindly get some help here. Thanks in advance.

You can't include images inside code chunks, this is the reason why you are getting this error message, just take it out of the code chunk.

1 Like

Along with what Andres has said, if you're in a situation where you'll have to insert a image from a code chunk (I can't imagine, though), you can use the knitr::include_graphics function.

2 Likes