vscode-R: Unable to attach active R terminal: `could not find function ".vsc.attach"`
Describe the bug
I updated R to the most recent version (4.2.0). As a consequence, I had to reinstall several packages, including languageserver. After this I am no longer able to attach the active R terminal to the active VS Code session. Instead, when I click the “R” button in the bottom right corner, I get the error Error in .vsc.attach() : could not find function ".vsc.attach" I tried reinstalling the R extension in VS Code as well, without any luck.
To Reproduce Steps to reproduce the behavior:
- Upgrade R to version 4.2’
- Install package
languageserver - Reinstall R extension (REditorSupport)
- Start new R terminal
- Click on R button in the bottom left corner
- See error
Do you want to fix by self?
If it’s just a tweak of settings, I might be able to do it myself.
setting.json (I doubt it’s related, but I can’t say for sure.)
"r.rterm.linux": "/opt/anaconda3/bin/radian",
// R command line options (i.e: --vanilla)
"r.rterm.option": [--no-save, --no-restore],
// Keeping focus when running
"r.source.focus": "editor",
// Use active terminal for all commands, rather than creating a new R terminal
"r.alwaysUseActiveTerminal": false,
// Use bracketed paste mode
"r.bracketedPaste": false,
// Enable R session watcher
"r.sessionWatcher": true,
// Delay in milliseconds before sending each line to rterm (only applies if r.bracketedPaste is false)
"r.rtermSendDelay": 8,
Expected behavior Start R kernel and and attaching to current session. R Help, plots, etc. opens in tab.
Screenshots

Environment (please complete the following information):
- OS: Ubuntu 20.04.4 LTS
- VSCode Version: 1.66.2
- R Version: 4.2.0
- vscode-R version: 2.4.0
Additional context
In addition to reinstalling languageserver, a wide number of packages had to be updated/reinstalled. In addition, when starting a new R terminal in R, it started and Anaconda’s (much) older R version. I had to copy the R executable from /bin/R to opt/anaconda3/envs/renv/bin/R to load the newly updated R version.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
@pehkawn The
init.Rshould only be sourced in interactive sessions. I updated the wiki:If the R session is non-interactive or is an RStudio session, then it should not source
init.R.Thanks, for the tip! Adding the following code snippet
at the beginning of
"~/.Rprofilethe solved the problem. =)I am experiencing a problem similar to the one discussed in this issue. Due to certain circumstances, I want to use R with “r.alwaysUseActiveTerminal”: true. Actually, I am using a supercomputer environment (Grid Engine) and need to use R while securing computing resources. When I launch R/Radian in that environment, the indicator in the bottom right corner of VS code shows “R: (not attached).” Even if I manually execute .vsc.attach() as told in this issue, it returns an error "Error in .vsc.attach(): could not find function “.vsc.attach”.
I have confirmed that I can execute .vsc.attach() without any problems/error messages when “r.alwaysUseActiveTerminal”: false", and the the bottom right indicates R is successfully attached. This might be off-topic, but I would really appreciate your help.
Then, as a workaround, the following configuration may work by loading
init.Rimmediately after R is started. https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher#advanced-usage-for-self-managed-r-sessionsYes,
~/.vscode-R/init.Rreferences another file/home/user/.vscode/extensions/reditorsupport.r-2.4.0/R/session/init.R.Contents
~/.vscode-R/init.R:Contents
~/.vscode/extensions/reditorsupport.r-2.4.0/R/session/init.R: