Vscode-r: More robust session watcher initialization

Created on 21 Jan 2020  路  3Comments  路  Source: Ikuyadeu/vscode-R

We could make session watcher script initialization more robust with the following applied:

  • init.R detects if environment variable TERM_PROGRAM=vscode. Only in VSCode it is effective.
  • ~/.Rprofile only sources init.R when ~/.vscode-R/init.R exists. Disabling r.sessionWatcher removes ~/.vscode-R/init.R so that user does not have to comment out or remove the source() line manually.

The only drawback of detecting TERM_PROGRAM=vscode is that if R is started in a pre-existing environment inside a terminal multiplexer (e.g. tmux and screen) whose server program is not started inside VSCode terminal, it won't get a TERM_PROGRAM=vscode environment variable. But user could always set this environment variable to force it.

This is related to https://github.com/Ikuyadeu/vscode-R/issues/190, https://github.com/Ikuyadeu/vscode-R/issues/195, https://github.com/randy3k/radian/issues/139. When user tries to disable session watcher by setting "r.sessionWatcher": false but leaves source(...) line in ~/.Rprofile or any other startup script, the use of all R sessions will be broken.

feature-request

Most helpful comment

All 3 comments

Thanks @randy3k!

Alternatively, one could make use of the env variable R_PROFILE_USER that points to a vscode generated .Rprofile. For example, vscode-R could generate ~/.vscode-R/.Rprofile and set R_PROFILE_USER to it in the integrated terminal.

Looks like we could use https://code.visualstudio.com/api/references/vscode-api#TerminalOptions to createTerminal so that the environment variable could be setup before the R terminal is started in VSCode terminal.

@renkun-ken It seems like in my case there was no .Rprofile in my working directory but I edited Rprofile in C:\Program Files\R\R-3.6.1\library\base\R

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathaneastwood picture nathaneastwood  路  6Comments

gcambray picture gcambray  路  4Comments

tdeenes picture tdeenes  路  5Comments

MaTo04 picture MaTo04  路  5Comments

michaelHL picture michaelHL  路  5Comments