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

Handle more gracefully non-supported path syntax by Pandoc on Windows #31

Closed
olivroy opened this issue Jun 8, 2023 · 4 comments
Closed
Labels
bug an unexpected problem or unintended behavior feature a feature request or enhancement pandoc Related to upstream issue, limitation or else with Pandoc

Comments

@olivroy
Copy link

olivroy commented Jun 8, 2023

Hi,
thanks for the great package.

On windows, using

pandoc::pandoc_convert(file = "~/../file.ext")
! Running Pandoc failed with following errorpandoc.exe: ~/../file.ext withBinaryFile: does not exist (No such file or directory)
doesn't work.

I have to use (and it works)

pandoc::pandoc_convert(file = normalizePath("~/../file.ext"))

Maybe R could process first if the file exists before trying to run pandoc.

Also path with space doesn't work (no way to fix this other than to rename the file

pandoc::pandoc_convert(file = "~/../file with space.ext")
! Running Pandoc failed with following errorpandoc.exe: ~/../file withBinaryFile: does not exist (No such file or directory)
doesn't work.

(Notice the absence of the rest of the file name in the error message)

Thanks!
Running with latest R package version and pandoc 3.1.1

@olivroy olivroy changed the title pandoc_convert() preprocess the file on Windows pandoc_convert() errors with non-standard paths on Windows Jun 8, 2023
@cderv
Copy link
Owner

cderv commented Jun 9, 2023

Those are Pandoc errors. 🤔

Maybe R could process first if the file exists before trying to run pandoc.

In first case we can indeed resolve the path and normalize. I think this would work and have no issue. I just don't want to use absolute path everywhere though just to handle this specific syntax ~/.. that Pandoc path resolver does not handle. (possilbly a Pandoc issue in the first place

Also path with space doesn't work (no way to fix this other than to rename the file

The example you gave has also the other issue above. So is this link to the other issue ? Or do file with spaces not work at all, even when the path is not using the specific ~/.. syntax ?

It could be a quoting issue also when passing the file path as argument from R to pandoc command line

I also renamed the issue to reflect more the generic Pandoc relation

@cderv cderv added the feature a feature request or enhancement label Jun 9, 2023
@cderv cderv changed the title pandoc_convert() errors with non-standard paths on Windows Handle more gracefully non-supported path syntax by Pandoc on Windows Jun 9, 2023
@cderv cderv added the pandoc Related to upstream issue, limitation or else with Pandoc label Jun 9, 2023
@olivroy
Copy link
Author

olivroy commented Jun 9, 2023

Hi,

path with ~/

  1. It seems to be an issue with the "~/` notation in general. (indeed possibly a pandoc issue, but rmarkdown and quarto seem to resolve it)

file with space

  1. Sorry for the confusion, these are 2 different issues.

A path with space doesn't seem to work anywhere on Windows

See updated example with error message.

pandoc::pandoc_convert(file = "file with space.ext")
! Running Pandoc failed with following errorpandoc.exe: file withBinaryFile: does not exist (No such file or directory)
doesn't work.

@cderv
Copy link
Owner

cderv commented Jun 9, 2023

Thanks for testing !

I'll do the tweak for the resolving looking at how rmarkdown does it.

For the space, it seems an issue really in this package and quoting for the pandoc CLI as it seems to work with Pandoc CLI directly

> cd $env:TEMP
> echo "# test" > 'file with space.ext'
> cat '.\file with space.ext'
# test
> pandoc -t html '.\file with space.ext'
[WARNING] Could not deduce format from file extension .ext
  Defaulting to markdown
<h1 id="test">test</h1>
> rm '.\file with space.ext'
> cd

@cderv cderv added the bug an unexpected problem or unintended behavior label Jun 9, 2023
@cderv cderv closed this as completed in 628302f Aug 23, 2023
@cderv
Copy link
Owner

cderv commented Aug 23, 2023

We now use path.expand to handle the ~.

Regarding the space, I think it is already working. I can't reproduce and I already have test for this which is passing

test_that("pandoc_convert() handles space in file path", {
skip_on_cran()
skip_if_offline()
suppressMessages(pandoc_install())
local_pandoc_version("latest")
tmp_dir <- withr::local_tempdir()
writeLines("# My Markdown", "my test.md")
expect_no_error(pandoc_convert("my test.md", to = "html"))
expect_no_error(pandoc_convert("my test.md", to = "html", output = "my test.html"))
expect_true(fs::file_exists("my test.html"))
})

Is this happening for you with a specific Pandoc version maybe ?

I am closing this as space in file is working for me. Please reopen or a new one with new information if something is still not working with dev version

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 feature a feature request or enhancement pandoc Related to upstream issue, limitation or else with Pandoc
Projects
None yet
Development

No branches or pull requests

2 participants