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.
See also my comment https://github.com/Ikuyadeu/vscode-R/pull/184#issuecomment-575968505
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
Most helpful comment
See also my comment https://github.com/Ikuyadeu/vscode-R/pull/184#issuecomment-575968505