Skip to content

Commit

Permalink
Use R_PROFILE_USER
Browse files Browse the repository at this point in the history
  • Loading branch information
renkun-ken committed Jan 21, 2020
1 parent a093a01 commit 8963e39
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
9 changes: 9 additions & 0 deletions R/.Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if (file.exists(".Rprofile")) {
source(".Rprofile")
} else if (file.exists("~/.Rprofile")) {
source("~/.Rprofile")
}

if (is.null(getOption("vscodeR"))) {
source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
}
17 changes: 15 additions & 2 deletions src/rTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use strict";

import os = require("os");
import path = require("path");

import { pathExists } from "fs-extra";
import { isDeepStrictEqual } from "util";
import { commands, Terminal, window } from "vscode";
import { commands, Terminal, window, TerminalOptions } from "vscode";

import { getSelection } from "./selection";
import { removeSessionFiles } from "./session";
Expand All @@ -18,7 +21,17 @@ export function createRTerm(preserveshow?: boolean): boolean {
const termOpt: string[] = config.get("rterm.option");
pathExists(termPath, (err, exists) => {
if (exists) {
rTerm = window.createTerminal(termName, termPath, termOpt);
let termOptions: TerminalOptions = {
name: termName,
shellPath: termPath,
shellArgs: termOpt
};
if (config.get("sessionWatcher")) {
termOptions.env = {
R_PROFILE_USER: path.join(os.homedir(), ".vscode-R", ".Rprofile")
};
}
rTerm = window.createTerminal(termOptions);
rTerm.show(preserveshow);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const sessionDir = path.join(".vscode", "vscode-R");

export function deploySessionWatcher(extensionPath: string) {
resDir = path.join(extensionPath, "dist", "resources");
const srcPath = path.join(extensionPath, "R", "init.R");
const targetDir = path.join(os.homedir(), ".vscode-R");
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
const targetPath = path.join(targetDir, "init.R");
fs.copySync(srcPath, targetPath);

fs.copySync(path.join(extensionPath, "R", "init.R"), path.join(targetDir, "init.R"));
fs.copySync(path.join(extensionPath, "R", ".Rprofile"), path.join(targetDir, ".Rprofile"));
}

export function startResponseWatcher(sessionStatusBarItem: StatusBarItem) {
Expand Down

0 comments on commit 8963e39

Please sign in to comment.