-
Notifications
You must be signed in to change notification settings - Fork 136
R Session watcher
This experimental feature is still under development and the behavior may change without notice. Please file an issue here if you experience problems or have any suggestions.
An opt-in experimental R session watcher is implemented to support the following features:
- Watch any R session
- Show value of session symbols on hover
- Provide completion for session symbols
-
View()any objects including data frames and list objects - Show plot output on update and plot history
- Show htmlwidgets, documentation and shiny apps in WebView
Known limitations:
- Session watcher only works when the R session is started from the workspace folder in VSCode.
- Session watcher may not work with folders under some cloud drives (e.g. Google Drive, OneDrive) but works with iCloud Drive on macOS.
To enable this feature, turn on r.sessionWatcher in VSCode settings, reload or restart VSCode, and the session watcher will be activated automatically
on R sessions launched by vscode-R via R: Create R Terminal command.
If you previously appended the source(...) line to ~/.Rprofile, you may safely remove it since the configuration for basic usage is automated. It is
now only necessary for advanced usage described below.
For advanced users to work with self-managed R sessions (e.g. manually launched R terminal or started in tmux or screen window), some extra
configuration is needed. Follow the steps below to make R session watcher work with any external R session:
-
Turn on
r.sessionWatcherin VSCode settings. -
Edit
.Rprofilein your home directory by running the following code in R:file.edit("~/.Rprofile") -
Append the following code to the file:
source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
-
Restart or Reload Window in VSCode
If the workspace folder you open in VSCode already has a .Rprofile, you need to append the code above in this file too because ~/.Rprofile will not
be executed when a local .Rprofile is found.
The script only works with environment variable TERM_PROGRAM=vscode. the script will not take effect with R sessions started in a tmux or screen window that does not have it, unless this environment variable is manually set before sourcing init.R, for example, you may insert a line Sys.setenv(TERM_PROGRAM="vscode") before it.
For the case of basic usage, turning off r.sessionWatcher in VSCode settings is sufficient
to disable R session watcher.
For the case of advanced usage, user should, in addition, comment out or remove the source(...) line appended to ~/.Rprofile.
This script writes the metadata of symbols in the global environment and plot file to ${workspaceFolder}/.vscode/vscode-R/PID where PID is the R process ID. It also captures user input and append command lines to ${workspaceFolder}/.vscode/vscode-R/response.log, which enables the communication between vscode-R and a live R sesson.
Each time the extension is activated, the latest session watcher script (init.R) will be deployed to ~/.vscode-R/init.R.
R sessions started from the workspace root folder will be automatically attached. The session watcher is designed to work in a wide range of scenarios:
- Official R terminal or
radianconsole - R session started by vscode-R or user
- R session in a
tmuxorscreenwindow - Switch between multiple running R sessions
- Remote Development via SSH, WSL and Docker
The status bar item shows the process id of the attached R session. Click the status bar item and it will attach to currently active session.


The R terminal used in the screenshot is radian which is cross-platform and supports syntax highlighting, auto-completion and many other features.
- Getting Started
- Installation
- Configuration
- Features
- Package development
- R Markdown
- Contributing
- FAQ