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

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

Open
FGL-Linear opened this issue Feb 17, 2023 · 3 comments

Comments

@FGL-Linear
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants