ZPeh
ZPeh

Reputation: 612

R Markdown: openBinaryFile: does not exist (No such file or directory)

I've developed a shiny app that allows user to download a HTML report via R Markdown. I'm trying to include custom css and images into my rmarkdown file. However, I keep getting this error message:

pandoc: Could not fetch (either css or image file)
openBinaryFile: does not exist (No such file or directory)

When I knit the .rmd file on R Studio, it is able to reference the image file or css that I want. However, when I run the Shiny app and download the html file, I get the above error message. I've even tried to put the images and css files in the same working directory as the .rmd file, but to no avail...

output:
  html_document:
   css: pandoc.css

(same error message as above)

Been trying to find a solution for this but can't seem to...can anyone help here?

Upvotes: 29

Views: 47678

Answers (8)

Jona Engel
Jona Engel

Reputation: 369

I just ran into the same message when running:

pandoc -s foo.html foo.md

Where I totally missed the -o flag as it should have been

pandoc -s -o foo.html foo.md

With the latter, everything is working like a charm.

Upvotes: 1

Lodewijk Bergmans
Lodewijk Bergmans

Reputation: 11

I had a similar error message, but in my case the problem was that I used a # symbol in one of the chunk titles:

```{r show distribution of # of commits per month}

Which is no problem if you just run the notebook in Rstudio, but apparently confuses knitr/pandoc: when knitting, I got an error message like

pandoc: <path>/figure-html/show distribution of : openBinaryFile: does not exist (No such file or directory)`)

Removing the # from the chunk title solved the problem.

Upvotes: 1

Max Gordon
Max Gordon

Reputation: 5467

I recently ran into the issue on my Windows work-computer where I simply set the .libPaths() in the Rprofile.site file. This in line with previous answers but a little more detailed.

Step 1

Check your current paths:

> .libPaths()
[1] "\\\\my_work_server.se/some_subdir$/username/Dokument/R/win-library/3.6"
[2] "C:/R/R-3.6.3/library"

Step 2

Look for the \\\, in this case it is the path "\\\\my_work_server.se/some_subdir$/username/Dokument/R/win-library/3.6". This path is most likely some already mounted home directory, in my case it is H: = "\\\\my_work_server.se/some_subdir$/username/. If you don't have a mounted directory you may want to fix this first or change the library path to another.

Step 3

So if you've installed R under C:/R/R-3.6.3/ you edit the file C:/R/R-3.6.3/etc/Rprofile.site and add:

.First <- function(){
  .libPaths(c("H:/Dokument/R/win-library/3.6", "C:/R/R-3.6.3/library"))
}

Remember to change H: to where you have your mounted network directory.

Step 4

That's it, restart R and you should be able to knit your document.

Upvotes: 4

deef123
deef123

Reputation: 11

I have been having a similar issue, with RStudio, rmarkdown and pandoc on a windows machine with network filestore. I followed various advice, mapped the drive to a letter and it still didn't help.

Eventually, I discovered that one of the paths in my libPaths contained the network location/Universal path. I updated that libpath to the mapped letter drive and everything seems to be going well!

Upvotes: 1

Kodiakflds
Kodiakflds

Reputation: 623

I believe that I had the same issue. I first had tried Changing the Default Directory but every time I went to knit the RMarkdown file, I would get the same set of errors indicating that the process was still trying to access files on my Network's H drive rather that my local C drive, specifically it was looking in the rmarkdown library file on the network drive. I thought I was following the advice above, but after that did not work I tried deleting the rmarkdown folder in the network drive

eg: \\fwnew12\Home\My Documents\R\win-library\3.6\rmarkdown.

This seemed to force R to only use my local C drive (C:/Program Files/R/R-3.6.3/library) and finally successfully knit a PDF. Maybe this is not a recommended approach, but I just need something that works.

Upvotes: 0

Zeno Lee
Zeno Lee

Reputation: 21

The issue that I had with RStudio & the pandoc error (openBinaryFile error) was due to the file path in which the project was created and loaded.

Project File Path

When I created the project, I created it using the Universal path, which is the 2nd option in the image above. However, when I changed this to the mapped drive letter, the option above it, my pandoc error was gone.

I'm running RStudio 1.2.1335 and R version 3.4.4

Upvotes: 1

AColeman
AColeman

Reputation: 555

I just had this issue as well, but for me the reason was that the RStudio project was on a shared drive, and I had opened it through the network location. The problem was resolved when I closed out of the project, and opened it back up through a mapped network drive. (If when you run getwd() your location starts with \\, this is probably what is happening to you.)

Upvotes: 22

Haloom
Haloom

Reputation: 360

I had a similar problem. I was not using the full file path. I was using ~/path/to/file. I changed it to the full path (i.e. removed the ~/) and it worked.

Upvotes: 14

Related Questions