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

Render With R Markdown can't handle Windows paths #3816

Closed
tjmahr opened this issue Jul 2, 2024 · 2 comments
Closed

Render With R Markdown can't handle Windows paths #3816

tjmahr opened this issue Jul 2, 2024 · 2 comments
Assignees
Labels
bug Something isn't working lang: r support

Comments

@tjmahr
Copy link

tjmahr commented Jul 2, 2024

Positron Version: 2024.06.1-27

Steps to reproduce the issue:

  1. Run Windows
  2. Open a .Rmd file.
  3. Click Render with R Markdown

What did you expect to happen?

If Powershell is the terminal, the " around the path are gobbled up:

> rmarkdown::render(c:\\Users\\mahr\\Desktop\\s.Rmd)
Error: unexpected '\\' in "rmarkdown::render(c:\\"
Execution halted

 *  The terminal process "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command & 'C:\Program Files\R\R-4.4.0\bin\x64\R.exe' -e 'rmarkdown::render("c:\\Users\\mahr\\Desktop\\s.Rmd")'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Which seems to be an issue: https://stackoverflow.com/questions/44840644/how-do-i-escape-quotes-in-a-powershell-string

If Git Bash is the terminal, the backslashes lose escaping.

> rmarkdown::render("c:\Users\mahr\Desktop\s.Rmd")
Error: '\U' used without hex digits in character string (<input>:1:23)
Execution halted

 *  The terminal process "C:\Program Files\Git\bin\bash.exe '--login', '-i', '-c', ''C:\Program Files\R\R-4.4.0\bin\x64\R.exe' -e 'rmarkdown::render("c:\\Users\\mahr\\Desktop\\s.Rmd")''" terminated with exit code: 1. 

In regular old Command Prompt, we lose the quotes again.

> rmarkdown::render(c:\\Users\\mahr\\Desktop\\s.Rmd)
Error: unexpected '\\' in "rmarkdown::render(c:\\"
Execution halted

 *  The terminal process "C:\windows\System32\cmd.exe /d /c ""C:\Program Files\R\R-4.4.0\bin\x64\R.exe" -e "rmarkdown::render("c:\\Users\\mahr\\Desktop\\s.Rmd")""" terminated with exit code: 1. 

Were there any error messages in the output or Developer Tools console?

I included the errors. Nothing appeared in the Developer Tools console.

@tjmahr tjmahr added the bug Something isn't working label Jul 2, 2024
@tjmahr tjmahr changed the title Render With R Markdown Render With R Markdown can't handle Windows paths Jul 2, 2024
@jennybc
Copy link
Member

jennybc commented Jul 2, 2024

This looks like another case of #2194.

Update: actually, closer to #2123.

@jennybc jennybc self-assigned this Jul 2, 2024
@juliasilge juliasilge added this to the Release Candidate milestone Jul 8, 2024
jennybc added a commit that referenced this issue Jul 17, 2024
…owerShell (#3909)

Addresses #3816 by using `vscode.ProcessExecution` instead of
`vscode.ShellExecution`, to bypass some tricky quoting issues presented
by PowerShell, without doing our own quoting or writing (much) OS- or
shell-specific code.

The problem is that we want to execute a code snippet like
`rmarkdown::render("whatever.Rmd")` (where `"whatever.Rmd"` needs to be
interpolated in, which is really neither here nor there). So you need
quotes around this file path. But using `ShellExecution` you also need
quotes around the whole `rmarkdown::render()` snippet; let's say these
are single quotes. And, when executed in PowerShell, the entire command
_also_ gets double quoted, which then changes the context for the quotes
in the code snippet, leading to much misery:

```
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command &
'C:\Program Files\R\R-4.3.3\bin\x64\R.exe' -e 'rmarkdown::render("d:\Users\jenny\rmd-render-
fun\test.Rmd")'" terminated with exit code: 1. 
```

By the time you get to R, the double quotes around the file path have
gone missing (since I captured this error, I have changed the path
separators here as well; but also that is not the problem):

```
> rmarkdown::render(d:\Users\jenny\rmd-render-fun\test.Rmd)
Error: unexpected symbol in "rmarkdown::render(d:\Users"
Execution halted
```

I tried all sorts of things, trying to stick with
`vscode.ShellExecution` and `vscode.ShellQuoting` but never succeeded in
finding a combination of argument strings and quoting that worked on
Windows (PowerShell) and macOS. I became increasingly convinced, similar
to this issue microsoft/vscode#187661, that it
might be impossible.

### QA Notes

Exercise these commands on multiple OSes:

* *R: Render Document with R Markdown*, find this in the command palette
* *R: Source R File*, find this in the command palette or use the "play"
button

Here's a repo I used for experimentation while working on this PR:
https://github.com/jennybc/rmd-render-fun.

You could grab it with

```r
usethis::create_from_github("https://github.com/jennybc/rmd-render-fun", destdir = "~/tmp")
```

Substitute your favorite destination directory for experiments in
`destdir`. This folder sports 2 `.Rmd` files, with and without spaces in
the filename, and likewise for `.R`.
@jonvanausdeln
Copy link
Contributor

Verified Fixed

Positron Version(s) : 2024.07.0-85
OS Version(s) : Windows 11, Ubuntu 22

Test scenario(s)

RMarkdown files now render as expected on Windows

Link(s) to TestRail test cases run or created:

TestRail RMarkdown Test

Automated test added to nightly smoke tests.

jonvanausdeln added a commit that referenced this issue Jul 23, 2024
### Intent

Add a simple test to render an RMarkdown file, in support of testing #3816

### Approach

Added jsut 1 test to render using the command palette command. Of note, this is our first use of the ms provided terminal object. 

Update full test ci to install pandoc

### QA Notes

Passes in CI. Not added to PR workflow.

_note_ - to run locally, you need to install pandoc. It is bundled into a release build, but it's not bundled with dev builds.

https://pandoc.org/installing.html
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working lang: r support
Projects
None yet
Development

No branches or pull requests

5 participants