Skip to content
Merged
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@
"r.helpPanel.rpath": {
"type": "string",
"default": "",
"markdownDescription": "Path to an R executable. Defaults to `r.rterm.XXX`. Must be \"vanilla\" R, not radian etc.! "
"markdownDescription": "Path to an R executable. Must be \"vanilla\" R, not radian etc.! Will be read from registry or path if not set."
},
"r.helpPanel.helpProvider": {
"type": "string",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createRTerm, deleteTerminal,
runSelectionInTerm, runTextInTerm } from './rTerminal';
import { getWordOrSelection, surroundSelection } from './selection';
import { attachActive, deploySessionWatcher, globalenv, showPlotHistory, startRequestWatcher } from './session';
import { config, ToRStringLiteral, getRpath } from './util';
import { config, ToRStringLiteral, getRpath, getRpathFromSystem } from './util';
import { launchAddinPicker, trackLastActiveTextEditor } from './rstudioapi';
import { RMarkdownCodeLensProvider, RMarkdownCompletionItemProvider, runCurrentChunk, runAboveChunks } from './rmarkdown';

Expand Down Expand Up @@ -50,7 +50,7 @@ export async function activate(context: ExtensionContext) {
const rExtension = new RExtension();

// get the "vanilla" R path from config
let rPath = config().get('helpPanel.rPath', '') || await getRpath();
let rPath = config().get<string>('helpPanel.rpath', '') || await getRpathFromSystem();
if(rPath.match(/^[^'"].* .*[^'"]$/)){
rPath = `"${rPath}"`;
}
Expand Down
46 changes: 29 additions & 17 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,55 @@ function getRfromEnvPath(platform: string) {
return '';
}

export async function getRpathFromSystem() {

let rpath: string = '';
const platform: string = process.platform;

if ( platform === 'win32') {
// Find path from registry
try {
const key = new winreg({
hive: winreg.HKLM,
key: '\\Software\\R-Core\\R',
});
const item: winreg.RegistryItem = await new Promise((c, e) =>
key.get('InstallPath', (err, result) => err === null ? c(result) : e(err)));
rpath = path.join(item.value, 'bin', 'R.exe');
} catch (e) {
rpath = '';
}
}

rpath ||= getRfromEnvPath(platform);

return rpath;
}

export async function getRpath() {

let rpath: string = '';
const platform: string = process.platform;

if ( platform === 'win32') {
rpath = config().get<string>('rterm.windows');
if (rpath === '') {
// Find path from registry
try {
const key = new winreg({
hive: winreg.HKLM,
key: '\\Software\\R-Core\\R',
});
const item: winreg.RegistryItem = await new Promise((c, e) =>
key.get('InstallPath', (err, result) => err === null ? c(result) : e(err)));
rpath = path.join(item.value, 'bin', 'R.exe');
} catch (e) {
rpath = '';
}
}
} else if (platform === 'darwin') {
rpath = config().get<string>('rterm.mac');
} else if (platform === 'linux') {
rpath = config().get<string>('rterm.linux');
}

rpath ||= await getRpathFromSystem();

if (rpath === '') {
rpath = getRfromEnvPath(platform);
}
if (rpath !== '') {
return rpath;
}

window.showErrorMessage(`${process.platform} can't use R`);
return undefined;
}


export function ToRStringLiteral(s: string, quote: string) {
if (s === undefined) {
return 'NULL';
Expand Down