-
Notifications
You must be signed in to change notification settings - Fork 390
Description
I was using scoop to install R (via the main bucket), RStudio and Quarto (both via cderv/r-bucket). However, I found a wired issue that RStudio errored when rendering quarto documents saying that:
ERROR: Error executing 'C:\Users\hongy\scoop\apps\r\current\bin\Rscript': 系统找不到指定的文件。 (os error 2)
Unable to locate an installed version of R.
Install R from https://cloud.r-project.org/
But directly running quarto render test.qmd from command line works.
After some search though the codebase, I found that rBinaryPath("Rscript") was called to run Rscript with given arguments. rBinaryPath() internally uses QUARTO_R, R_HOME and Windows Registry entry to locate the bin directory under the R installation folder. Then use bin/Rscript.exe as the target path.
Lines 14 to 33 in af5c051
| export const rRunHandler: RunHandler = { | |
| canHandle: (script: string) => { | |
| return [".r"].includes(extname(script).toLowerCase()); | |
| }, | |
| run: async ( | |
| script: string, | |
| args: string[], | |
| stdin?: string, | |
| options?: RunHandlerOptions, | |
| ) => { | |
| return await execProcess({ | |
| cmd: [ | |
| await rBinaryPath("Rscript"), | |
| script, | |
| ...args, | |
| ], | |
| ...options, | |
| }, stdin); | |
| }, | |
| }; |
However, this did not work if R was installed via scoop in RStudio. There are several related issues here:
If R was installed via scoop:
- There is no Windows Register key written
- The
Rscipt.exewas only atbin\x64|x32\Rscript.exe, and scoop did not create links forRscript.exeunder thebinfolder. See: https://github.com/ScoopInstaller/Main/blob/master/bucket/r.json#L22-L40 - Shims for
Rscript.exe,R.exe,Rterm.exeand etc. were created under~/scoop/shims. This folder was added to the user PATH so that every other program can access them. This is why directly runningquarto renderfrom the command line works.rBinaryPath("Rscript")will use the path thatwhich("Rscript")returns.
However, when quarto was called in R, since the R_HOME environment variable was automatically created. rBinaryPath("Rscript") will use R_HOME/bin/Rscript.exe which does not exist.
One solution maybe is instead of directly returning R_HOME/bin/Rscript.exe:
- Check if the path exists
- If not, try testing
R_HOME/bin/{arch}/Rscript.exe