When knitting: invalid version specification ‘getAppUserDataDirectory:sHGetFolderPath:’

Hi all,

I have written up and am trying to knit an R Markdown file. The file is formatted correctly, with no offending code in the body that might cause an error. However, when I try to knit the file (using the "knit" button), I encounter the error

pandoc.exe: getAppUserDataDirectory:sHGetFolderPath: illegal operation (unsupported operation)
Error in strsplit(info, "\n")[[1]] : subscript out of bounds
Calls: <Anonymous> ... pandoc_available -> find_pandoc -> lapply -> FUN -> get_pandoc_version
In addition: Warning message:
In system(paste(shQuote(path), "--version"), intern = TRUE) :
  running command '"D:/Program Files/Pandoc/pandoc.exe" --version' had status 1
Execution halted

While debugging, I tried using rmarkdown::find_pandoc() and rmarkdown::pandoc_available, which also yield similar errors:

> rmarkdown::find_pandoc()
Error: invalid version specification ‘getAppUserDataDirectory:sHGetFolderPath:’
In addition: Warning message:
In system(paste(shQuote(path), "--version"), intern = TRUE) :
  running command '"D:/Program Files/Pandoc/pandoc.exe" --version' had status 1

> rmarkdown::pandoc_available()
Error: invalid version specification ‘getAppUserDataDirectory:sHGetFolderPath:’
In addition: Warning message:
In system(paste(shQuote(path), "--version"), intern = TRUE) :
  running command '"D:/Program Files/Pandoc/pandoc.exe" --version' had status 1

Other things I have tried:

  • Set the RSTUDIO_PANDOC path to a custom installation of pandoc
  • Reinstalled RStudio
  • Followed the suggestions/hints here and here, to no avail

Has anyone encountered a similar problem, or have any insights into what I can do?

It seems that your Pandoc binary is not working correctly, or at least as we expect.

Can you try running pandoc.exe --version from your terminal on Windows from where it is installed ? (or use full path instead of pandoc.exe

Also can you try

rmarkdown:::find_program("pandoc")

what is the returned value ?

Both commands seem to recognise my installation of pandoc.

Running pandoc.exe --version in my windows terminal yields

C:\Windows\System32>pandoc.exe --version

pandoc.exe 2.18
Compiled with pandoc-types 1.22.2, texmath 0.12.5, skylighting 0.12.3,
citeproc 0.7, ipynb 0.2, hslua 2.2.0
Scripting engine: Lua 5.4
User data directory: C:\Users\Timothy\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

And rmarkdown:::find_program("pandoc") yields

> rmarkdown:::find_program("pandoc")
                                 pandoc 
"D:\\Program Files\\Pandoc\\pandoc.exe"

That is not the same version as found by rmarkdown

Does this binary exists on your system ? Does it work ?
Is RSTUDIO_PANDOC set to this pandoc binary ?

Hi cderv,

I mentioned in my original post that I had installed pandoc separately to see if this would resolve my issues - this is why the version was v2.18 (latest pandoc version) and not v2.17 (the version included with RStudio).

I have now reverted to v2.17 by uninstalling v2.18 and repeated the steps you mentioned. RSTUDIO_PANDOC now points to the default directory:

> Sys.getenv("RSTUDIO_PANDOC")
[1] "D:/Program Files/RStudio/bin/quarto/bin"

And I confirmed this by checking in cmd:

C:\Users\Timothy>"D:/Program Files/RStudio/bin/quarto/bin/pandoc.exe" --version
pandoc.exe 2.17.1.1
Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
citeproc 0.6.0.1, ipynb 0.2
User data directory: C:\Users\Timothy\AppData\Roaming\pandoc
Copyright (C) 2006-2022 John MacFarlane. Web:  https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

But when I try looking for pandoc in R, nothing is there:

> rmarkdown:::find_program('pandoc')
pandoc 
    "" 

Using other commands in rmarkdown invokes errors identical to the ones described in the original post:

> rmarkdown:::pandoc_available()
Error: invalid version specification ‘getAppUserDataDirectory:sHGetFolderPath:’
In addition: Warning message:
In system(paste(shQuote(path), "--version"), intern = TRUE) :
  running command '"D:/Program Files/RStudio/bin/quarto/bin/pandoc.exe" --version' had status 1

> rmarkdown:::find_pandoc()
Error: invalid version specification ‘getAppUserDataDirectory:sHGetFolderPath:’
In addition: Warning message:
In system(paste(shQuote(path), "--version"), intern = TRUE) :
  running command '"D:/Program Files/RStudio/bin/quarto/bin/pandoc.exe" --version' had status 1

This is really an uncommon error, and I believe it comes from Pandoc. I think if you try pandoc --version in your terminal without R you'll get the same issue.

Which OS / environment are you on ?

I found some similar issue on Windows AZURE (Pandoc on Microsoft Azure gives getAppUserDataDirectory error - Super User and Pandoc on Microsoft Azure gives getAppUserDataDirectory error · Issue #7486 · jgm/pandoc · GitHub)

it seems that somehow, the user data dir is not correctly found. Pandoc uses a default data dir (Pandoc - Pandoc User’s Guide) which should be on Windows: C:\Users\USERNAME\AppData\Roaming\pandoc
Are you on windows ?

Modifying the --data-dir could solve the issue. (Using pandoc_args in each YAML header for you document) or setting probably XDG_DATA_HOME env var.
However, I am not sure why this does not work on your system. This would be an issue for Pandoc

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.