Why Pandoc does not retrieve the image file?

2019-03-12 21:18发布

问题:

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. I don't know how to resolve this. Please help.

回答1:

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 http://rmarkdown.rstudio.com/authoring_rcodechunks.html 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.



回答2:

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)


回答3:

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.



回答4:

@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.