Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandoc_convert fails when a path contains unexpanded tilde and a space #2089

Open
daattali opened this issue Apr 1, 2021 · 3 comments
Open
Assignees
Labels
bug an unexpected problem or unintended behavior next to consider for next release theme: paths path related improvment / issue

Comments

@daattali
Copy link

daattali commented Apr 1, 2021

This has come up because {rappdirs} created paths containing a tilde and a space r-lib/rappdirs#37, and that causes pandoc_convert to fail with error

pandoc.exe: ~/foo bar/test.md: openBinaryFile: does not exist (No such file or directory)
Error: pandoc document conversion failed with error 1

I see this behaviour on both MacOS and Windows.

For example, on Mac:

  • Create a file at ~/foo bar/test.md with the content of # test
  • Running rmarkdown::pandoc_convert("~/foo bar/test.md") fails
  • But running any of the following works:
    • rmarkdown::pandoc_convert("/Users/dean/foo bar/test.md")
    • rmarkdown::pandoc_convert(path.expand("~/foo bar/test.md"))

I'm not sure if the problem is with the pandoc software itself or with the rmarkdown function. Regardless, if the bug is in pandoc, then rmarkdown can perhaps fix this by always expanding tilde

@cderv
Copy link
Collaborator

cderv commented Apr 1, 2021

I don't think pandoc does the expansion: jgm/pandoc#3135 and currently rmarkdown::pandoc_convert() does not do it either. It is a thin wrapper to pandoc and input is passed as-is to pandoc command line. All our functions that uses rmarkdown::pandoc_convert() does take care of the path, and usually we run pandoc from root folder of the Rmd file (changing the working directory for the rendering) to avoid any issue in path. Are you using pandoc_convert() directly ?

We could indeed normalize the path in this function for the input. 🤔

@daattali
Copy link
Author

daattali commented Apr 1, 2021

I am indeed using pandoc_convert (it's an exported function so I had no reason to think I shouldn't; is it not considered safe?) see here https://github.com/daattali/addinslist/blob/18dfef8c7f93dd9b7b2297622b34ce08e23e2271/R/utils.R#L32

I fixed the problem in my case by performing tilde expansion, but I think it would be good to solve it closer to the root = here

@cderv
Copy link
Collaborator

cderv commented Apr 1, 2021

I am indeed using pandoc_convert (it's an exported function so I had no reason to think I shouldn't; is it not considered safe?)

I was just curious and check I did understood correctly. You can use it safely.

I fixed the problem in my case by performing tilde expansion, but I think it would be good to solve it closer to the root = here

Thanks for the suggestion that makes sense!

@cderv cderv added bug an unexpected problem or unintended behavior next to consider for next release labels Jan 4, 2022
@cderv cderv self-assigned this Jan 4, 2022
@cderv cderv moved this to Backlog in R Markdown Team Projects Jan 4, 2022
@cderv cderv moved this from Backlog to Todo in R Markdown Team Projects Jan 4, 2022
@cderv cderv added the theme: paths path related improvment / issue label Jan 10, 2022
@cderv cderv moved this from Todo to To discuss in R Markdown Team Projects Mar 8, 2022
@cderv cderv moved this from To discuss to Backlog in R Markdown Team Projects Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior next to consider for next release theme: paths path related improvment / issue
Projects
Status: Backlog
Development

No branches or pull requests

2 participants