15

On RStudio version 0.98.501 I had a long .Rmd file which was easily converted to html once I clicked KnitHtml button. The Knitting process, as I understand, created several folders including images (some manually added by myself), figures, cache and a knitHtml folder which included final .html file. I recently downloaded RStudio version 0.98.894 (preview release) because I wanted to use more features. Now, when I click KnitHtml I get following error:

pandoc.exe: Failed to retrieve C:/Users/durraniu/Documents/Trajectory1/images/vissim-view.png InvalidUrlException "C:/Users/durraniu/Documents/Trajectory1/images/vissim-view.png" "Invalid scheme" Error: pandoc document conversion failed with error 61

I copied all the images including the vissim-view.png as indicated above, from the images folder to the knitHtml folder and clicked the button again. This time it gave the same error related to image file which R would create i.e a plot. How to resolve this?

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
umair durrani
  • 5,597
  • 8
  • 45
  • 85
  • 3
    Never use absolute paths unless you absolutely have to. Use relative paths whenever you can. Put your image under the same directory as the Rmd file, and use `![](vissim-view.png)`. – Yihui Xie Jun 07 '14 at 05:52
  • 1
    Pandoc on Windows is not great at handling paths. If you want, you can revert to 0.98.501's KnitToHTML behavior by adding the comment `` to your document. See [Migrating from RMarkdown V1](http://rmarkdown.rstudio.com/authoring_migrating_from_v1.html). – Jonathan Jun 07 '14 at 13:12
  • 1
    @Jonathan Thanks for the suggestion. I wanted to use rmarkdown version 2 to add table of contents. It seems to me now, after Yihui's comment, that it is almost impossible to knit a Rmd file created on an older version of RStudio in a new version. I either have to change the paths of all images or be content without table of contents. By the way, thank you Yihui I will keep this in my mind to not use absolute paths next time. – umair durrani Jun 07 '14 at 16:36
  • 1
    @umairdurrani If a relative path works, please write it as the answer and mark it as accepted (you are welcome to answer your own question on SO). – Yihui Xie Jun 08 '14 at 05:34
  • @Yihui Changing to relative paths worked perfectly, it created table of contents and displayed all figures. However after some time I clicked knitHtml again to make sure `cache=TRUE`was working but got the following error with no output: `pandoc.exe: Could not find data file ./Trajectory1-new_files/figure-html/pdf_velocity.png Error: pandoc document conversion failed with error 97`. Please note that I copied all the images to the same directory where Rmd file resides. I don't know if its me or a bug in preview release of RStudio. – umair durrani Jun 09 '14 at 18:45
  • It knits perfectly if I change `cache=FALSE`. But gives error as above with `cache=TRUE` in global chunk options. – umair durrani Jun 09 '14 at 20:41
  • @Jonathan does it mean that I can't use rmarkdown v2 on Windows? Hope this gets fixed soon as I am keen to use Shiny in rmarkdown for my work! I work for a major bank and having this can potentially lead to great PR for the R community. Tks! – xiaodai Jul 10 '14 at 01:48
  • I am also having the same issue, using `cache = TRUE` results in an error (`pandoc.exe: Could not find image './tuto_files/figure-latex/wcex2.pdf', skipping...`). I am trying to find a workaround (because I am generating a pdf with ca. 100 figures), without success at the moment. – Boris Leroy Sep 24 '14 at 13:21

4 Answers4

11

While there are multiple correct solutions above, I'd like to add that a common cause of this error is syntactical, when the author accidentally wraps the file name in the markdown in quotes:

![my image]("my_image.png")

This will result in pandoc being unable to locate the file. I find this mistake to be easy to make in knitr, since we are intertwining R scripts with markdown.

The correct way to insert the image is:

![my image](my_image.png)
Megatron
  • 15,909
  • 12
  • 89
  • 97
3

I encountered a similar error like this: pandoc.exe: Could not find data file ProjectPart1_files/figure-html/sample_Mean_versus_Theoretical_Mean-1.png Error: pandoc document conversion failed with error 97

And one sentence from this page solved my problem.

"If you run into problems with cached output you can always clear the knitr cache by removing the folder named with a _cache suffix within your document’s directory."

When the error occurred, there exactly existed a folder with name like "ProjectPart1_cache" in the working directory. After I deleted it, the error was removed.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Tom
  • 3,168
  • 5
  • 27
  • 36
2

@Yihui's comment above was the answer that worked for me, and it's not a current answer here, so I'm adding it:

"Never use absolute paths unless you absolutely have to. Use relative paths whenever you can. Put your image under the same directory as the Rmd file, and use ![](vissim-view.png)."

Using a relative path worked for me where an absolute path did not.

BLT
  • 2,492
  • 1
  • 24
  • 33
1

Sadly, Jonathan's answer in the comments worked for me. I added:

<!-- rmarkdown v1 -->

To my document, and it did the trick. He claims that this is because Pandoc on Windows is not great at handling paths.

If someone else would write a better answer, I will gladly erase this one.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Tal Galili
  • 24,605
  • 44
  • 129
  • 187