Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup with conda installed R: attaching active Terminal fails #1487

Open
skwde opened this issue Feb 12, 2024 · 6 comments
Open

Setup with conda installed R: attaching active Terminal fails #1487

skwde opened this issue Feb 12, 2024 · 6 comments
Labels

Comments

@skwde
Copy link

skwde commented Feb 12, 2024

Describe the bug
conda installed packages are not found;
not possible to attach active terminal session.

To Reproduce

Use following environment file to install R

---
name: r
channels:
  - conda-forge
dependencies:
  - r-base
  - r-renv
  - r-languageserver
  - r-httpgd
  - radian

and run

conda create -f environment.yml

to install the environment.

Ensure the settings as mentioned below.

Next clikc on R: (not attached) in the status bar in VSCode and get the error

The terminal process "<path to base>/.conda/envs/r/bin/radian '--no-save', '--no-restore'" terminated with exit code: 1.

Can you fix this issue by yourself? (We appreciate the help)

No

(If applicable) Please attach setting.json

"r.rpath.linux": "<path to base>/.conda/envs/r/bin/R",
"r.rterm.linux": "<path to base>/.conda/envs/r/bin/radian",

"r.libPaths": ["<path to base>/.conda/envs/r/lib/R/library"],

Expected behavior
Terminal should attach

Screenshots
If applicable, add screenshots to help explain your problem.
You can show the keyboard contents by pressing F1 and Developer: toggle screencast mode

Environment (please complete the following information):

  • OS: macOS 14.2.1 with vscode server on rocky 8.6
  • VSCode Version:1.86.1
  • R Version: 4.3.2
  • vscode-R version: v2.8.2

Additional context
I already tried what is suggested here https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher#advanced-usage-for-self-managed-r-sessions as mentioned in this issue

EDIT:

There are also following related issues

@skwde skwde added the bug label Feb 12, 2024
@rfhb
Copy link

rfhb commented Feb 18, 2024

The system call to radian wrongly includes a comma after the first parameter:

"<omitted>/bin/radian '--no-save', '--no-restore'"

This seems unrelated to using conda or not, in my case without conda. I did not readily find the reason for why the system call is composed like this.

@skwde This worked for me to fix:

  • In VS Code, open setting r.rterm.option
  • Remove parameters and re-add parameters, one by one, --no-save and --no-restore
  • Open Terminal pane, add R Terminal

Subsequently, radian started for me as expected:

ps ax | grep radian
52731 s014  Ss+    0:01.91 <omitted>/MacOS/Python /usr/local/bin/radian --no-save --no-restore

@skwde
Copy link
Author

skwde commented Mar 4, 2024

@rfhb thanks for the suggestion but this doesn't solve the problem.

I tried re-adding as you suggested but the problem keeps reappearing.
I also tried

"r.rterm.option": [
        "--no-save --no-restore"
    ],

Then I get

The terminal process "<path to base>/.conda/envs/r/bin/radian '--no-save --no-restore'" terminated with exit code: 2.

It looks like the problem is that the parameters are included inside ''.

It actually also fails when I set

"r.rterm.option": [],
The terminal process "<path to base>/.conda/envs/r/bin/radian" terminated with exit code: 1.

@botsunny
Copy link

Hey there, did you find a solution to your problem?

@skwde
Copy link
Author

skwde commented Mar 27, 2024

@botsunny Unfortunately no...

@jondeans
Copy link

jondeans commented Apr 12, 2024

I have nearly the same environment set up and the same issue.

It's odd because running radian --no-save --no-restore from the CLI works fine and you can reproduce the same errors manually by adding in the quotes radian '--no-save --no-restore' or radian '--no-save', '--no-restore'

Setting r.bracketedPaste: true like the install instructions doesn't seem to work either.

{
  "r.bracketedPaste": true,
  "r.rterm.linux": "/home/user/.local/bin/radian"
}

My hunch is that if the options from the r.term.option list could be passed differently this would all go away, but I'm not familiar enough with VS Code extensions to attempt that fix here.

However!

Adding your R binary to the options list does seem to work for now.

{
    "r.rpath.linux": "/home/ec2-user/miniconda3/envs/ngs/bin/R",
    "r.rterm.linux": "/home/ec2-user/miniconda3/envs/ngs/bin/radian",
    "r.rterm.option": [
        "--no-save",
        "--no-restore",
        "--r-binary=/home/ec2-user/miniconda3/envs/ngs/bin/R"
    ]
}

@LucasMS
Copy link

LucasMS commented Sep 3, 2024

I hope this helps you guys.

A solution that I found was to work with conda + vscode + renv.

Each project that I work on has its own conda environments (stored at conda_envs), including one called r. I use renv to track and manage my R libraries. This is a bit different from managing your R libraries within conda. I work project-based, so each time I connect to a project, I open the VSCode in the project folder. I tell vscode to look for R in the project, so it always attaches the R of the project. Radian does not work (I have not tested it extensively though).

This is a reproducible set-up:

  1. At the project folder called project/, I have the r.yml file:
name: conda_envs/r
channels:
  - conda-forge
  - bioconda
  - defaults
dependencies:
  - r-base=4.1.2
prefix: conda_envs/r
  1. Install conda environment and R packages using the conda environment and renv
conda env create --prefix conda_envs/r -f r.yml
conda activate conda_envs/r
# Install packages using renv
# If you have conda_envs in .gitignore, do not need to do it.
echo "conda_envs" > .renvignore
R -e 'install.packages(c("renv"), repos = "http://cran.us.r-project.org")'
R -e 'renv::init()'
R -e 'renv::install(c("languageserver", "httpgd", "jsonlite", "rlang"))' # libs necessary for vscode
  1. Settings for vscode:
{
    "r.plot.useHttpgd": true,
    "r.rpath.linux": "${workspaceFolder}/conda_envs/r/bin/R",
    "r.rterm.linux": "${workspaceFolder}/conda_envs/r/bin/R" // radian will not work
}
  1. Go to the folder as base directory: File --> Open Folder...

  2. Open a new R terminal (I normally go to + on terminal tab and select R terminal

Still trying to figure out how to get radian working in this setup. I think the trick is to tell radian which R to use, for instance $ env R_HOME=/usr/local/lib/R radian. But I could not find a solution for my case where each project has its own R version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants