Christophe,

I've been having a similar problem, but hadn't gotten around to posting a question about it. After reading this thread, I also tried changing the default directory and I was able to knit rmarkdown documents successfully.

In my current set-up, I remote into a secure cloud server, which is where I do all my R coding. But all my files (personal packages, R projects, etc.) are stored on a separate network drive. The default directory path for a project looks like this:

"\\\\securefiles/mydepartment/Users/Joel/projects/myproject"

When I try knitting a document to PDF, I get the following error:

Error: pandoc document conversion failed with error 1

But the securefiles network drive is already mapped to drive letter Z: on the cloud server. So I changed the default directory to this:

"Z:/mydepartment/Users/Joel/projects/myproject"

After this change, I was able to knit the document without error.

My question is, how do I get RStudio to always use the mapped Z: drive as the default directory path?

Not sure how to answer that. Bottom line is I have two issues that my IT folks can't seem to resolve.

(1) The RStudio IDE would not allow me to save *.R or *.Rmd files. I read were the UNC may not like the actually file path to external network locations and if there is a letter associated with the path to use that drive letter as the default working directory. Whereas by default the working directory in the Tools - Options is ~ I reset mine to use the drive letter (and path) and that seems to have taken care of the saving issue.
(2) The other issue is a (apparently) Pandoc.exe in that RStudtio can't find the location. Not sure best but best guess. I'll check into the link you originally sent tomorrow when I get into work. I also would if it how my IT folk update our systems (remotely) had if it might not be better if they physically load R/RStudio as an administer to insure links are made. But my guess is it has to do with the funky path names and maybe R Studio just gets confused. I did notice that the knit output doesn't use the disk letter code path but rather the full path names. So again I'm wondering if its a path names issue.

I'll see if I can't at lest re-type the knit output tomorrow

1 Like

Here is the problematic R Notebook code:

output file: lkj-.knit.md

"C:/Program Files/RStudio/bin/pandoc" +RTS -K512m lkj-.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output lkj-,html --email-obfuscation none --self-contained --standalone --section-divs --template "\coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme"bootstrap" --include-in-header "C:\Users\al52975\AppData\Local\Temp\RtmpmQKdWo\rmarkdown-strdb07d0bf7d.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --lua-filter "\coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Documents/R/win-library/3.6/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "\coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Documents/R/win-library/3.6/rmarkdown/rmd/lua/latex-div.lua"
pandoc.exe: \: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversaion failed with error 1
Execution halted

There is some thought that the following path "\coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html" used by RStudio is incorrect it should be "\coe.ic.gov\Home\ESDC\nga_home_052\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html". Is there a way to change or programmatically change that to see

Christophe

How do you change the default directory? Do you change it via the Tools-Global Options-Default working directory ......

@reichmaj thank you that is interesting. I feel the issue is with this network path pass as argument to Pandoc

--template "\coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html"

basically you rmarkdown :package: installation is on another network drive and Pandoc does not find this path to be correct. Is this path above correct and working when you paste it in an explorer window ?

I don't know if it is Pandoc that does not deal correctly or rmarkdown that does not create the correct command line to pandoc. Or even RStudio IDE which does something different with this path thing.

I know Pandoc has fixed some issues in the past, and I think you are using an old version because still using RStudio 1.2.
can you check ?

rmarkdown::pandoc_version()

You can use a recent version of Pandoc by following

That would be the first thing to do to rule Pandoc version.

Other check would be to see what these 2 commands returns

system.file("rmarkdown", "lua", "latex-div.lua", package = "rmarkdown")
rmarkdown::pkg_file_lua("latex-div.lua")

can you run them ?

Also on your computer, does H:// is for \coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\ ?

Then if you're willing to help more, we could try several things like just running Pandoc command line to see how it works or try to enter debug mode to see how the path is maybe modified.

My IT folks seem to think the problem maybe associated with

--template "\coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html"

they say the actual path should be

--template "\coe.ic.gov\Home\ESDC\nga_home_052\al52975\My Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html"

However both paths take me to the same html page.

rmarkdown::pandoc_version()

[1] '2.7.2'

system.file("rmarkdown", "lua", "latex-div.lua", package = "rmarkdown")

[1] ""

assuming I typed correctly

rmarkdown::pkg_file_lua("latex-div.lua")

Error : 'pkg_file_lua' is not an exported object from 'namespace:rmarkdown'

yes H: == \coe.ic.gov\Home\ESDC\NGA_HO~2\al52975\ actually is should be
`\coe.ic.gov\Home\ESDC\nga_home_052\al52975" my IT folks seem to think the "NGA_HO~2" is the issue?????

Pandoc version could be involved or not - Last version 2.11.4. You can download one to use or upgrade RStudio 1.4 which has a newer version. I don't know if it is the problem but just saying if you want to try

And I forgot to asked you the rmarkdown version you were using... it seems not a recent one. I should have guessed it with the path above - sorry
So we'll simplify can you just run to see what path R use for the package ?

system.file(package = "rmarkdown")

Paths with ~ are usually short path name on Windows (see utils::shortPathName() in R).
We'll try something to see if this is related. Not sure it will work though.
I'll answer back while you check the above

Here is a code to try and see what works and does not work - hope you'll understand it to modify it if I missed something about your environment.
I have put this to run in a temp directory but you also not run the 2 first commands and 2 last to execute this in the same work dir as your R Markdown file.

dir.create(tmp_dir <- tempfile())
owd <- setwd(tmp_dir)

xfun::write_utf8(c(
  "---", 
  "title: test",
  "---", 
  "",
  "# dummy",
  ""
), "test.md")

convert <- function(template) {
  rmarkdown::pandoc_convert(
    "test.md",
    to = "html",
    from = "markdown",
    output = "test.html",
    verbose = TRUE,
    options = c("--template", template)
  )
}
# with path computed from R not modified by rmarkdown - should fail ?
convert(system.file("rmd/h/default.html", package = "rmarkdown"))
# with path computed from R but modified by rmarkdown - should work ?
convert(rmarkdown::pandoc_path_arg(system.file("rmd/h/default.html", package = "rmarkdown")))
# manual path - short path with ~
convert("\\coe.ic.gov\\Home\\ESDC\\NGA_HO~2\\al52975\\My Documents\\R\\win-library\\3.6\\rmarkdown\\rmd\\h\\default.html")
convert("//coe.ic.gov/Home/ESDC/NGA_HO~2/al52975/My Documents/R/win-library/3.6/rmarkdown/rmd/h/default.html")
# manual path - long path without ~
convert("\\coe.ic.gov\\Home\\ESDC\\nga_home_052\\al52975\\My Documents\\R\\win-library\\3.6\\rmarkdown\\rmd\\h\\default.html")
convert("//coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Documents/R/win-library/3.6/rmarkdown/rmd/h/default.html")
# manual path - using letter
convert("H:\\My Documents\\R\\win-library\\3.6\\rmarkdown\\rmd\\h\\default.html")
convert("H:/My Documents/R/win-library/3.6/rmarkdown/rmd/h/default.html")

# reseting work dir an cleaning
setwd(owd)
unlink(tmp_dir, recursive = TRUE)

ok I'll give your code a try. What about the direction of back slashes // verse \

ok I'll give your code a try. What about the direction of back slashes / verse \

Never mind it would appear that is what you are asking me to do in the code

Windows can work with both I think and I know there could be issues so I think it worth a try with both. To write the paths you are mentioning above in Understanding R Markdown Output Code - #13 by reichmaj with \...\...\ , this need to be escaped in R using \\ that is why there is two instead of one. Because of R escape for backslash in R.

Don't forget to check this please:

system.file(package = "rmarkdown")

so that we know how R return you network path exactly

Is this code run from within said R Notebook or external fro the R script command line?

You should run it from an R script in your R console. Not inside a Rmd file.

system.file(package = "rmarkdown")

[1] "\\coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Document/R/win-library/3.6/rmarkdown"

Thanks for this. So the full path without the letter H: is what R sees.

When you paste this in an explorer windows do they both work

  • Two backslashes : \\coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Document/R/win-library/3.6/rmarkdown
  • One backslashes:\coe.ic.gov/Home/ESDC/nga_home_052/al52975/My Document/R/win-library/3.6/rmarkdown

I wonder if these two backslashes are the issue here. Pandoc had an issue with these

Fixed in Pandoc 2.11 it seems: Command line options: use normalizePath in more places. · jgm/pandoc@26ed7fb · GitHub

We'll know for sure if there is still an issue in Pandoc if you can upgrade and test it

I have a fix. I 'm running an older version of RStudio version 1.0.143 and everything is working. I found a zipped file, unzipped it, and ran the *.exe. Every thing is working so this would appear to be an issue with my version (1.2.5033 and the windows 10 configuration I have to live with ???). So at this point I guess I wait until my IT folks upgrade both R and RStudio (and RTools).
-- Jeff

This could mean that using a different Pandoc version fix your issue. Which is the version of Pandoc with this ?

You can rule out Pandoc once you'll test both version with same version of Pandoc. If so, then it could be a RStudio bug.

You can also rule out RStudio 1.2, by running the rmarkdown::render() outside of RStudio (or in a background session using callr - this would require setting the path to PANDOC correctly so that it is found when you are outside of RStudio)

rmarkdown::pandoc_version()

[1] '1.17.2'

How would I test both versions with same version of Pandoc, given Pandoc is loaded with the RStudio files?

Wow this is a really old one! You'll loose some features of rmarkdown with such an old version.
Pandoc 2.0 brought a lot of new stuff we have built on.

So your issue maybe fixed because you downgraded Pandoc. The command line you should see should be fairly different than the previous one I think. If you want to share maybe this could help.

It is here above :Understanding R Markdown Output Code - #12 by cderv

Ok so I tried running RStudio (version 1.0.143) with Pandoc 2.7.2. Same issue came up. So might that suggest the Pandoc file is corrupted????

I'm also reading the reference you listed - 1.1 Use a Pandoc version not bundled with the RStudio IDE | R Markdown Cookbook