Unable to attach active R terminal: `could not find function ".vsc.attach"`

See original GitHub issue

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:

  1. Upgrade R to version 4.2’
  2. Install package languageserver
  3. Reinstall R extension (REditorSupport)
  4. Start new R terminal
  5. Click on R button in the bottom left corner
  6. 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 image

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
renkun-kencommented, May 5, 2022

@pehkawn The init.R should only be sourced in interactive sessions. I updated the wiki:

if (interactive() && Sys.getenv("RSTUDIO") == "") {
  source(file.path(Sys.getenv(if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"), ".vscode-R", "init.R"))
}

If the R session is non-interactive or is an RStudio session, then it should not source init.R.

2reactions
pehkawncommented, May 5, 2022

Thanks, for the tip! Adding the following code snippet

source(file.path(Sys.getenv(
   if (.Platform$OS.type == "windows") "USERPROFILE" else "HOME"
 ), ".vscode-R", "init.R"))

at the beginning of "~/.Rprofile the solved the problem. =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing R in VSCode: Interacting with an R session - Kun Ren
Looks like you did't enable r.sessionWatcher. You should set "r.sessionWatcher": true in vscode settings and reload vscode, then run command R: ...
Read more >
R not showing in Terminal - visual studio code - Stack Overflow
I want to get basic R working in VSCode then I'll connect with Radian. It keeps trying to run my R script using...
Read more >
R in Visual Studio Code
If you want to run an entire R file, open the file in the editor, and press Ctrl+Shift+S and the file will be...
Read more >
Cannot use VS Code + SSH connection for R coding - Reddit
The problem I have is that in VSC, even if I try to .vsc.attach() I still see that R is indeed not attached....
Read more >
How to run R in Visual Studio Code - InfoWorld
The vscode-R extension instructions suggests that users open a folder when working in R, not just create a new file. You can open...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found