Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare the
rmarkdown::render()
code snippet for the challenge of P…
…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`.
- Loading branch information