R session background connections
See original GitHub issueIn #394, notebook.R runs a socket connection that the notebook communicates with. Would it be worth extracting part of this out so that a socket connection is available for each R session started by the user? This would make the following possible:
- Sending VS Code’s R commands to the session invisibly, rather than having to send them as text to the console
- Querying the session, for example to get the names of data frames
- For
Run Selection/Line, potentially using R instead of TypeScript to choose which lines to send (allowing use of R’s parse functions) - Inline evaluation (sending user code to the session invisibly, and displaying the results in the editor) - this one’s not really necessary but some other languages/IDE’s have it and it’s kind of cool
@renkun-ken You wrote notebook.R and the session watcher, which has some overlap with this proposal, so you’re definitely the best person to comment. Does this sound practical? Let me know if I need to clarify anything.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (7 by maintainers)
Top Results From Across the Web
R session background connections · Issue #440 - GitHub
To use it, start an R session (any terminal works), create some variables etc., and then run vscDebugger::.vsc.listen() . To connect vscode ...
Read more >emacs - Background R console and long running session
In both client and server machine I run Debian 8 xfce. Is there a way to keep alive the R terminal while closing...
Read more >r_session: External R Session in callr: Call R from R - Rdrr.io
A permanent R session that runs in the background. This is an R6 class that extends the processx::process class.
Read more >Evaluate an expression in another R session, in the background
Starts evaluating an R function call in a background R process, and returns immediately. ... Whether to have a control connection to the...
Read more >Configuring Spark Connections - sparklyr - RStudio
Background. Using Spark and R inside a Hadoop based Data Lake is becoming a common practice at companies. Currently, there is no good...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In the branch linked above (vscDebugger/websocket) the debugger attaches to a tcp port that is run in the background (in a separate tcl thread apparently, not entirely sure myself…). After attaching, you need to enter any command in the R console to view the
Global Workspace, but after that the session is surprisingly robust when dealing with parallel execution etc.E.g. while running
the debug console is responsive and it’s even possible to change the value of variables in the gloabl env in the variables window.
Same seems to apply e.g. here:
Using the debugger in this mode seems to be semi-barebone (the commands entered into the R terminal itself are, the ones entered in the debug console definitely not), persistent (the R process can be started in an external terminal independent of vscode), and seems to be at least somewhat parallel-safe (see examples above?).
Thanks @andycraig for your proof of concept! I tried integrating this functionality in the debugger, using svSocket instead of a websocket.
This required some changes to the svSocket package which I commited here, but seems to work ok on windows and WSL. To try these out, install the branch vscDebugger/websocket and the modified version of svSocket. Then start an R session, call
vscDebugger::.vsc.startWebsocket()and launch the debugger in the example configAttach to R process.This mode is still a bit unstable, but you should be able to view the current workspace in the variable window and run commands in the debug console (autocomplete seems to be broken here for some reason), without blocking the user from using the normal terminal input.
This approach is of course somewhat limited by the fact that it can only be accessed through the debugger. But I think it would e.g. be possible to write a custom DAP-client that sends only the requests/commands you are interested in and displays the info in a custom interface.