ardata-fr / doconv

Other
13 stars 1 forks source link

Problem with PowerShell script using "\" instead of "/" in $indocx filepath #5

Open FGL-Linear opened 1 year ago

FGL-Linear commented 1 year ago

First of all, sorry if I say something stupid. I'm basically self-taught when it comes to R (well, anything computer-related really) so I may be commiting some noob mistakes.

docx_update() wasn't working for me so I tried to find out why. I got into the docx_update_win() source and ran it line by line and I think I found what's happening to me.

When the function writes the temporary PowerShell script, it uses "/" in the filepath of $indocx. When I manually changed the "/" to "\" it worked. I don't really understand why, as I read that Windows / PowerShell can use both types of slash... (Disclaimer: I know nothing about PowerShell).

I'm not really sure if this is really an issue of the function itself or if it's caused by some wrong config on my end. If needed, I will try to provide any additional information if asked.

Thank you for your time.

davidgohel commented 1 year ago

Sorry, it's working as expected on the Windows machines I could use for testing. / is not an issue.

If you have an error message, that helps. Without a clear description of your issue, it's not possible to help :)

FGL-Linear commented 1 year ago

Of course, sorry about that!

I get no error in R itself, though when I run lines 19:20 of docx_update_win(), res$stderr does contain an error message from powershell. It's full of \n, \r and other escapes, so I've run the script from powershell itself and attached a screenshot for readability:

doconv_ps

Sorry about the Spanish interface / error language. The first line says that it can not find the file.

DanChaltiel commented 4 months ago

I have the same problem, but it seems to happen only if there are spaces in the file name. In PowerShell, $Word.Documents.Open("C:\Users\d_chaltiel\test test.docx") will work but $Word.Documents.Open("C:/Users/d_chaltiel/test test.docx") will not.

Unfortunately, doconv:::absolute_path() enforces the separator to be "/" so there seems to be no way to solve the problem outside the package.

The only workaround I found was to copy the input in a temporary file to get rid of spaces:

docx2pdf2 = function(input, output = gsub("\\.(docx|doc|rtf)$", ".pdf", input)){
  x = tempfile(fileext=".docx")
  file.copy(input, x)
  doconv::docx2pdf(x, output)
}

I feel your pain of dealing with that ridiculous habit of Windows using antislashes as a file separator!