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 .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Yes / No

```json
// R.exe path for windows
"r.rterm.windows": "C:\\Program Files\\R\\R-3.4.4\\bin\\x64\\R.exe",
"r.rterm.windows": "",

// R path for Mac OS X
"r.rterm.mac": "/usr/local/bin/R",
Expand Down
2 changes: 1 addition & 1 deletion ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Yes / No

```json
// R.exe path for windows
"r.rterm.windows": "C:\\Program Files\\R\\R-3.4.4\\bin\\x64\\R.exe",
"r.rterm.windows": "",

// R path for Mac OS X
"r.rterm.mac": "/usr/local/bin/R",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Requires [R](https://www.r-project.org/).

## Usage

* For Windows, set config `r.rterm.windows` to your `R.exe` Path like `"C:\\Program Files\\R\\R-3.3.4\\bin\\x64\\R.exe"`;
* For Windows, if `r.rterm.windows` is empty, then the path to `R.exe` will be searched in Windows registry. If your R is not installed with path written in registry or if you need a specific R executable path, set it to a path like `"C:\\Program Files\\R\\R-3.3.4\\bin\\x64\\R.exe"`.
* For Radian console, enable config `r.bracketedPaste`
* Open your *folder* that has R source file (**Can't work if you open only file**)
* Use `F1` key and `R:` command or `Ctrl+Enter`(Mac: `⌘+Enter`)
* Use `F1` key and `R:` command or `Ctrl+Enter` (Mac: `⌘+Enter`)

## Features

Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
"properties": {
"r.rterm.windows": {
"type": "string",
"default": "C:\\Program Files\\R\\R-3.5.0\\bin\\x64\\R.exe",
"default": "",
"description": "R.exe path for windows"
},
"r.rterm.mac": {
Expand Down Expand Up @@ -436,6 +436,7 @@
"@types/mocha": "^7.0.1",
"@types/node": "^13.7.6",
"@types/vscode": "^1.42.0",
"@types/winreg": "^1.2.30",
"copy-webpack-plugin": "^5.1.1",
"mocha": "^7.1.0",
"node-atomizr": "^0.6.1",
Expand All @@ -457,6 +458,7 @@
"jquery.json-viewer": "^1.4.0",
"path": "^0.12.7",
"popper.js": "^1.16.1",
"winattr": "^3.0.0"
"winattr": "^3.0.0",
"winreg": "^1.2.4"
}
}
55 changes: 28 additions & 27 deletions src/rTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,37 @@ import { removeSessionFiles } from "./session";
import { config, delay, getRpath } from "./util";
export let rTerm: Terminal;

export function createRTerm(preserveshow?: boolean): boolean {
const termName = "R Interactive";
const termPath = getRpath();
if (termPath === undefined) {
return undefined;
}
const termOpt: string[] = config.get("rterm.option");
pathExists(termPath, (err, exists) => {
if (exists) {
const termOptions: TerminalOptions = {
name: termName,
shellPath: termPath,
shellArgs: termOpt,
export async function createRTerm(preserveshow?: boolean): Promise<boolean> {
const termName = "R Interactive";
const termPath = await getRpath();
console.info(`termPath: ${termPath}`);
if (termPath === undefined) {
return undefined;
}
const termOpt: string[] = config.get("rterm.option");
pathExists(termPath, (err, exists) => {
if (exists) {
const termOptions: TerminalOptions = {
name: termName,
shellPath: termPath,
shellArgs: termOpt,
};
if (config.get<boolean>("sessionWatcher")) {
termOptions.env = {
R_PROFILE_USER_OLD: process.env.R_PROFILE_USER,
R_PROFILE_USER: path.join(os.homedir(), ".vscode-R", ".Rprofile"),
};
if (config.get<boolean>("sessionWatcher")) {
termOptions.env = {
R_PROFILE_USER_OLD: process.env.R_PROFILE_USER,
R_PROFILE_USER: path.join(os.homedir(), ".vscode-R", ".Rprofile"),
};
}
rTerm = window.createTerminal(termOptions);
rTerm.show(preserveshow);

return true;
}
window.showErrorMessage("Cannot find R client. Please check R path in preferences and reload.");
rTerm = window.createTerminal(termOptions);
rTerm.show(preserveshow);

return false;
});
}
return true;
}
window.showErrorMessage("Cannot find R client. Please check R path in preferences and reload.");

return false;
});
}

export function deleteTerminal(term: Terminal) {
if (isDeepStrictEqual(term, rTerm)) {
Expand Down
26 changes: 22 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
"use strict";

import { existsSync } from "fs-extra";
import path = require("path");
import { window, workspace } from "vscode";
import winreg = require("winreg");
export let config = workspace.getConfiguration("r");

export function getRpath() {
export async function getRpath() {
if (process.platform === "win32") {
return config.get<string>("rterm.windows");
let rpath: string = 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 = "";
}
}

return rpath;
}
if (process.platform === "darwin") {
return config.get<string>("rterm.mac");
Expand All @@ -25,7 +43,7 @@ export function ToRStringLiteral(s: string, quote: string) {
}

return (quote +
s.replace(/\\/g, "\\\\")
s.replace(/\\/g, "\\\\")
.replace(/"""/g, `\\${quote}`)
.replace(/\\n/g, "\\n")
.replace(/\\r/g, "\\r")
Expand All @@ -34,7 +52,7 @@ export function ToRStringLiteral(s: string, quote: string) {
.replace(/\\a/g, "\\a")
.replace(/\\f/g, "\\f")
.replace(/\\v/g, "\\v") +
quote);
quote);
}

export async function delay(ms: number) {
Expand Down