The sess package provides an IPC layer between an R session and a client (such as the VS Code R extension).
Transport:
- Unix domain sockets (macOS/Linux)
- Windows named pipes
Protocol:
- JSON-RPC 2.0 messages
- JSON Lines (JSONL, newline-delimited JSON) framing (one JSON message per line)
Start the client connection from R:
sess::connect(
pipe_path = NULL, # Character: pipe/socket path. NULL -> SESS_PIPE or session file fallback
use_rstudioapi = TRUE, # Logical: enable rstudioapi emulation
use_httpgd = TRUE # Logical: use httpgd for plotting if available
)If pipe_path is omitted, connect() resolves it in this order:
SESS_PIPEenvironment variable~/.vscode-R/sessions/{PID}.json(pipefield)
After connecting, sess sends an attach notification.
Example:
{
"jsonrpc": "2.0",
"method": "attach",
"params": {
"version": "4.5.0",
"pid": 12345,
"tempdir": "/tmp/Rtmp.../sess",
"wd": "/path/to/project",
"info": {
"command": "/usr/bin/R",
"version": "R version 4.5.0 (...) ",
"start_time": "2026-05-05 06:00:00"
}
}
}Transport uses JSON Lines (JSONL, newline-delimited JSON):
- sender writes one JSON-RPC object +
\n - receiver buffers stream chunks and dispatches complete lines only
This preserves JSON-RPC semantics while handling stream fragmentation safely.
{
"jsonrpc": "2.0",
"method": "method_name",
"params": {}
}{
"jsonrpc": "2.0",
"id": 1,
"method": "method_name",
"params": {}
}{
"jsonrpc": "2.0",
"id": 1,
"result": {}
}{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32601,
"message": "Method not found"
}
}notify_client() sends one-way events (no id), including:
attachdataviewplot_updatedhttpgdhelpbrowserwebviewrestart_rsend_to_console
request_client() sends JSON-RPC requests and waits for matching response id.
Used by RStudio API emulation methods, such as:
rstudioapi/active_editor_contextrstudioapi/replace_text_in_current_selectionrstudioapi/insert_or_modify_textrstudioapi/show_dialogrstudioapi/navigate_to_filerstudioapi/set_selection_rangesrstudioapi/document_saverstudioapi/get_project_pathrstudioapi/document_contextrstudioapi/document_save_allrstudioapi/document_newrstudioapi/document_close
Coordinate convention on the wire:
- rows/columns are 1-indexed (R-style)
- client may convert to internal 0-indexed representation
Client queries R state through JSON-RPC requests.
Request:
{"jsonrpc":"2.0","id":1,"method":"workspace","params":{}}Response (example):
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"globalenv": {
"my_df": {"class": ["data.frame"], "type": "list", "length": 11}
},
"search": ["package:stats", "package:graphics"],
"loaded_namespaces": ["sess", "utils"]
}
}Request params example:
{"width":800,"height":600,"format":"svglite"}Response example:
{"jsonrpc":"2.0","id":2,"result":{"format":"svglite","data":"<base64 or svg payload>"}}Request params example:
{"expr":"head(mtcars)"}Response example:
{"jsonrpc":"2.0","id":3,"result":{"str":"'data.frame': 6 obs. ..."}}Request params example:
{"expr":"mtcars","trigger":"$"}Response example:
{
"jsonrpc": "2.0",
"id": 4,
"result": [
{"name":"mpg","type":"double","str":"numeric"},
{"name":"cyl","type":"double","str":"numeric"}
]
}connect() initializes runtime hooks via register_hooks().
Intercepted features include:
utils::View()browser(),viewer(),page_viewer()- help topic rendering hooks
Relevant options:
sess.row_limitsess.dataviewsess.browsersess.webviewsess.helpPanel
To support reloads and attach workflows, the extension writes:
~/.vscode-R/sessions/{PID}.json
sess::connect() reads this file as fallback when direct pipe parameters are unavailable.
Changed:
- transport is now UDS / named pipe
- framing is JSON Lines (JSONL) over stream sockets
- authentication token exchange is removed
Unchanged:
- JSON-RPC method names and payload shapes
- request/response correlation by
id - high-level feature behavior (workspace, hover, completion, plot, dataview, RStudio API emulation)