Skip to content

Failed to locate Rscript.exe if R was installed via scoop in RStudio #995

@hongyuanjia

Description

@hongyuanjia

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.

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:

  1. There is no Windows Register key written
  2. The Rscipt.exe was only at bin\x64|x32\Rscript.exe, and scoop did not create links for Rscript.exe under the bin folder. See: https://github.com/ScoopInstaller/Main/blob/master/bucket/r.json#L22-L40
  3. Shims for Rscript.exe, R.exe, Rterm.exe and 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 running quarto render from the command line works. rBinaryPath("Rscript") will use the path that which("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:

  1. Check if the path exists
  2. If not, try testing R_HOME/bin/{arch}/Rscript.exe

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions