You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue running code line-by-line in vscode: Cannot determine RHOME #431
Describe the bug
Hi! I'm getting an error of Cannot determine R HOME when trying to execute code line-by-line in VSCode. This is a new problem which hadn't happened to me before, so I think an update might have broken some settings in some weird and wonderful way?
To Reproduce
Steps to reproduce the behavior:
Open a random R script
command + enter on the first line (which happens to say library(tidyverse) but this is irrelevant)
Do you want to fix by self?
I wish I could
(If yes,) what kind of help do you want? (e.g. Which file should I fix, Survey (related documents)
(If related)setting.json
// R path for Mac OS X"r.rterm.mac": "/Users/darya/anaconda3/bin/radian"// R command line options (i.e: --vanilla)"r.rterm.option": [],
// An optional encoding to pass to R when executing the file, i.e. 'source(FILE, encoding=ENCODING)'"r.source.encoding": "UTF-8",
// 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": true,
// Enable R session watcher (experimental)"r.sessionWatcher": true,
// Delay in milliseconds before sending each line to rterm (only applies if r.bracketedPaste is false)"r.rtermSendDelay": 8,
Expected behavior
I was hoping the code would run line by line...
Environment (please complete the following information):
OS: macOS 10.15.7 (19H2)
VSCode Version: Version: 1.50.1
R Version: 4.0.2
vscode-R version: v1.5.1
Additional context
Running /Users/darya/anaconda3/bin/radian (or radian) from the zsh command line results in R happily launching, and the library(tidyverse) code working without errors (as does running the script from RStudio)
What's wrong with my Config? Thanks in advance!
PS I have seen the issue here - but can't seem to fix the R RHOME issue by using the tips there.
Sorry I might have poorly grabbed the config. Biggest difference was that originally I had it set that I was NOT always using the active terminal and it didn't work.
Instead, when I set it to always use the active terminal, launched R from the vscode terminal, and then tweaked the brackets setting so no extra characters were being added it seems to work.
With "r.alwaysUseActiveTerminal": false, when you press ctrl+enter on an R document, it will run r.createRTerm command to launch an R session automatically.
In your settings, "r.rterm.mac": "/Users/darya/anaconda3/bin/radian" will make vscode-R launch radian instead of R. It seems that you could successfully run radian manually in VSCode terminal, but vscode-R cannot launch radian but fails with Cannot determine R HOME? You could simply verify this by pressing F1 and run R: Create R terminal command and it should produce the same error.
Looks like something is missing in the environment variables to launch radian by R: Create R terminal, something different from your zsh terminal in vscode. Not sure if this is a VSCode-specific problem?
Where did you install R? It may be possible that you have a different PATH variable in VSCode. I recall that there is an option in VSCode to inherit the environment variables from the shell. You may want to check that out.
Reacted by Diego A. Pacheco, Kevin Lee, Janko Thyson, Federica Brando, Sadjad Zamani, Michael Steinbaugh, Wenrong Shi, Renee Gil, Christof Kaufmann, Shensuo Li and 1 more
It looks like some important environment variables are missing when vscode-R launches radian via window.createTerminal(termOptions). I guess we should use what https://github.com/ManuelHentschel/VSCode-R-Debugger/blob/master/src/installRPackage.ts#L26 does: sending R terminal command to the shell in vscode terminal so that the environment variables from the shell (e.g. zsh) could be inherited.
It looks like some important environment variables are missing when vscode-R launches radian via window.createTerminal(termOptions). I guess we should use what https://github.com/ManuelHentschel/VSCode-R-Debugger/blob/master/src/installRPackage.ts#L26 does: sending R terminal command to the shell in vscode terminal so that the environment variables from the shell (e.g. zsh) could be inherited.
Actually, we may need to check this first:
"terminal.integrated.inheritEnv": true
If it is false, then the VSCode integrated terminal will not inherit environment variables from the system terminal, leading to this issue. Therefore, I recommend first checking if it can start normally in the system terminal. If it can, then it is likely that there is a problem with this configuration option.
Activity
renkun-ken commentedon Oct 27, 2020
Looks like randy3k/radian#219
dvanic commentedon Oct 27, 2020
@renkun-ken Thanks - yes, setting
Fixes the problem.
Why does this happen, though?
renkun-ken commentedon Oct 27, 2020
Looks like you haven't changed any settings?
dvanic commentedon Oct 27, 2020
Sorry I might have poorly grabbed the config. Biggest difference was that originally I had it set that I was NOT always using the active terminal and it didn't work.
Instead, when I set it to always use the active terminal, launched R from the vscode terminal, and then tweaked the brackets setting so no extra characters were being added it seems to work.
renkun-ken commentedon Oct 27, 2020
With
"r.alwaysUseActiveTerminal": false, when you pressctrl+enteron an R document, it will runr.createRTermcommand to launch an R session automatically.In your settings,
"r.rterm.mac": "/Users/darya/anaconda3/bin/radian"will make vscode-R launchradianinstead ofR. It seems that you could successfully runradianmanually in VSCode terminal, but vscode-R cannot launchradianbut fails withCannot determine R HOME? You could simply verify this by pressingF1and runR: Create R terminalcommand and it should produce the same error.dvanic commentedon Oct 27, 2020
Yes, it does produce the same error. Any advice on how to fix it?
renkun-ken commentedon Oct 28, 2020
Looks like something is missing in the environment variables to launch
radianbyR: Create R terminal, something different from your zsh terminal in vscode. Not sure if this is a VSCode-specific problem?@randy3k @andycraig any idea on why this could happen?
randy3k commentedon Oct 28, 2020
Where did you install R? It may be possible that you have a different PATH variable in VSCode. I recall that there is an option in VSCode to inherit the environment variables from the shell. You may want to check that out.
renkun-ken commentedon Oct 28, 2020
@dvanic Maybe you need to specify the following in your vscode settings?
dvanic commentedon Oct 29, 2020
@renkun-ken
Specifying that in the VSCode settings did indeed solve the problem!
It does generate a warning of :
But then libraries load and code executes.
I am curious, though, how to get it to properly
since I've got a few custom functions in that, and VSCode is clearly not picking them up...
renkun-ken commentedon Oct 29, 2020
It looks like some important environment variables are missing when vscode-R launches
radianviawindow.createTerminal(termOptions). I guess we should use what https://github.com/ManuelHentschel/VSCode-R-Debugger/blob/master/src/installRPackage.ts#L26 does: sending R terminal command to the shell in vscode terminal so that the environment variables from the shell (e.g. zsh) could be inherited.renkun-ken commentedon Oct 29, 2020
@dvanic You might try installing the vsix from https://github.com/renkun-ken/vscode-R/actions/runs/334838489 and see if it works now.
github-actions commentedon Jun 2, 2022
This issue is stale because it has been open for 365 days with no activity.
github-actions commentedon Jun 16, 2022
This issue was closed because it has been inactive for 14 days since being marked as stale.
brunomioto commentedon Mar 31, 2024
I got this error and fixed it by adding R to my PATH (it broke after I updated R)
Link: https://www.r-bloggers.com/2023/02/fixing-my-broken-vscode-setup-for-r/
ChristofKaufmann commentedon Apr 9, 2024
Note for an R installation (in linux) using a conda environment named
rthe path is like"/PATH/TO/CONDA/envs/r/lib/R"EndCredits commentedon Jan 15, 2026
Actually, we may need to check this first:
If it is false, then the VSCode integrated terminal will not inherit environment variables from the system terminal, leading to this issue. Therefore, I recommend first checking if it can start normally in the system terminal. If it can, then it is likely that there is a problem with this configuration option.