diff --git a/README.md b/README.md index a2a3671f..c891f2bb 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Go to the [wiki](https://github.com/REditorSupport/vscode-R/wiki) to view the do The following software or extensions are recommended to enhance the experience of using R in VS Code: -* [radian](https://github.com/randy3k/radian): A modern R console that corrects many limitations of the official R terminal and supports many features such as syntax highlighting and auto-completion. +* [radian](https://github.com/randy3k/radian): A modern R console that corrects many limitations of the official R terminal and supports many features such as syntax highlighting and auto-completion. By default, the extension will use vanilla R. To prefer radian, set `r.rterm.preferRadian` to `true`. * [VSCode-R-Debugger](https://github.com/ManuelHentschel/VSCode-R-Debugger): A VS Code extension to support R debugging capabilities. diff --git a/package.json b/package.json index 840963d4..8d184a2d 100644 --- a/package.json +++ b/package.json @@ -1325,6 +1325,11 @@ "default": "", "markdownDescription": "R path for interactive terminals (Linux). Can also be radian etc. Some variables defined in such as `${userHome}`, `${workspaceFolder}`, `${fileWorkspaceFolder}`, and `${fileDirname}` are supported." }, + "r.rterm.preferRadian": { + "type": "boolean", + "default": false, + "markdownDescription": "Prefer radian over vanilla R when radian is available on PATH. When `false` (default), vanilla R will be used." + }, "r.rterm.option": { "type": "array", "default": [ @@ -2041,3 +2046,4 @@ "REditorSupport.r-syntax" ] } + diff --git a/src/util.ts b/src/util.ts index b4e280af..38b86539 100644 --- a/src/util.ts +++ b/src/util.ts @@ -41,7 +41,7 @@ export function substituteVariables(str: string): string { return result; } -function getRfromEnvPath(platform: string) { +function getRfromEnvPath(platform: string, executableName: string = 'R') { let splitChar = ':'; let fileExtension = ''; @@ -52,7 +52,7 @@ function getRfromEnvPath(platform: string) { const os_paths: string[] | string = process.env.PATH ? process.env.PATH.split(splitChar) : []; for (const os_path of os_paths) { - const os_r_path: string = path.join(os_path, 'R' + fileExtension); + const os_r_path: string = path.join(os_path, executableName + fileExtension); if (fs.existsSync(os_r_path)) { return os_r_path; } @@ -67,7 +67,7 @@ export async function getRpathFromSystem(): Promise { rpath ||= getRfromEnvPath(platform); - if ( !rpath && platform === 'win32') { + if (!rpath && platform === 'win32') { // Find path from registry try { const key = new winreg({ @@ -135,6 +135,21 @@ export async function getRterm(): Promise { const configEntry = getRPathConfigEntry(true); let rpath = config().get(configEntry); rpath &&= substituteVariables(rpath); + + if (!rpath) { + const platform: string = process.platform; + const preferRadian = config().get('rterm.preferRadian', false); + + if (preferRadian) { + // Try radian first, then fall back to R + rpath = getRfromEnvPath(platform, 'radian') || getRfromEnvPath(platform, 'R'); + } else { + // Try R + rpath = getRfromEnvPath(platform, 'R'); + } + } + + // Fall back to system R path if still not found rpath ||= await getRpathFromSystem(); if (rpath !== '') {