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
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,16 @@
"type": "string"
}
},
"r.rterm.preferredConsoles": {
"type": "array",
"default": [
"R"
],
"markdownDescription": "Ordered list of R console executable names to search for on `PATH` when no explicit terminal path is set (e.g. `r.rterm.linux`). The first entry found on `PATH` will be used. Examples: `arf`, `radian`, `R`.",
"items": {
"type": "string"
}
},
"r.libPaths": {
"type": "array",
"items": {
Expand Down Expand Up @@ -2042,4 +2052,4 @@
"extensionDependencies": [
"REditorSupport.r-syntax"
]
}
}
20 changes: 17 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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 @@ -51,7 +51,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 @@ -66,7 +66,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 @@ -134,6 +134,20 @@ 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 preferredConsoles = config().get<string[]>('rterm.preferredConsoles', ['R']);

for (const consoleName of preferredConsoles) {
rpath = getRfromEnvPath(platform, consoleName);
if (rpath) {
break;
}
}
}

// Fall back to system R path if still not found
rpath ||= await getRpathFromSystem();

if (rpath !== '') {
Expand Down