Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,11 @@
"default": "",
"markdownDescription": "R path for interactive terminals (Linux). Can also be radian etc. Some variables defined in <https://code.visualstudio.com/docs/editor/variables-reference> 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": [
Expand Down Expand Up @@ -2041,3 +2046,4 @@
"REditorSupport.r-syntax"
]
}

21 changes: 18 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand All @@ -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;
}
Expand All @@ -67,7 +67,7 @@ export async function getRpathFromSystem(): Promise<string> {

rpath ||= getRfromEnvPath(platform);

if ( !rpath && platform === 'win32') {
if (!rpath && platform === 'win32') {
// Find path from registry
try {
const key = new winreg({
Expand Down Expand Up @@ -135,6 +135,21 @@ export async function getRterm(): Promise<string | undefined> {
const configEntry = getRPathConfigEntry(true);
let rpath = config().get<string>(configEntry);
rpath &&= substituteVariables(rpath);

if (!rpath) {
const platform: string = process.platform;
const preferRadian = config().get<boolean>('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 !== '') {
Expand Down