Skip to content

Activate conda environments prior to creating R kernel sessions #10788

Merged
jmcphers merged 18 commits into
mainfrom
feature/conda-activate-for-r
Dec 2, 2025
Merged

Activate conda environments prior to creating R kernel sessions #10788
jmcphers merged 18 commits into
mainfrom
feature/conda-activate-for-r

Conversation

@jmcphers

@jmcphers jmcphers commented Nov 25, 2025

Copy link
Copy Markdown
Collaborator

This change:

  • Makes the Conda R setting visible, with an experimental tag.
  • Decorates discovered Conda R environments with Conda: env_name in the picker.
  • Runs conda activate inside the shell that runs Conda R kernels, using a new kernel supervisor feature. This feature is also intended to support other preflight commands in the future. e.g. module load (Support interpreter environments defined by Environment Modules #8075).
image

The bulk of this change lives in the kernel supervisor: posit-dev/kallichore#55

Supersedes #10471.

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

This change brings in a new supervisor version that has more sophisticated startup handling to support the new features, so it is worth checking that old settings like "Run in Shell" continue to work.

wesm and others added 7 commits November 7, 2025 16:58
When R is installed in a conda/mamba environment, the conda environment
must be activated to ensure compilation tools and dependencies are
available in PATH. This change implements full conda environment
activation when starting R sessions from conda-based installations.

Key changes:
- Added condaEnvironmentPath field to RMetadataExtra and RInstallation
- Created conda-activation module to activate conda/mamba environments
  and capture environment variables
- Updated kernel spec creation to merge conda environment variables
- Added experimental positron.r.interpreters.condaDiscovery setting to UI
- Supports both conda and mamba, with platform-specific activation

The conda discovery setting is opt-in (default: false) and clearly
marked as experimental in the settings UI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 25, 2025

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical

readme  valid tags

@jmcphers jmcphers requested review from juliasilge and wesm November 25, 2025 16:28
@wesm

wesm commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

I tried building this branch and testing it out but couldn't get it working, maybe something wrong with my environment (macOS)

image

@jmcphers

Copy link
Copy Markdown
Collaborator Author

@wesm did you run npm install after pulling the branch? (the error looks like a supervisor version mismatch, which would happen if you didn't get the new version of the supervisor along with the rest of the code)

@juliasilge

Copy link
Copy Markdown
Member

I was able to build it successfully, but when I try to start an existing conda R env that I have, I see this:

Screenshot 2025-11-25 at 5 24 25 PM
R 4.4.2 (Conda: my-fantastic-r-env) failed to start up (exit code 1)

The kernel exited before a connection could be established

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

Comment thread extensions/positron-r/package.nls.json Outdated
Co-authored-by: Julia Silge <julia.silge@gmail.com>
Signed-off-by: Jonathan <jonathan@posit.co>
juliasilge
juliasilge previously approved these changes Nov 26, 2025

@juliasilge juliasilge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what I reported in #10788 (comment) was totally a "me" problem; I had cleaned out all the conda activation business out of my dot files at some point. 🙈

Once I did conda init, I could in fact start up my conda R environment and run code, make plots, etc:

Image

I was not able to use install.packages() for a package that contains compiled code, which is the problem reported in #10359. This change does not set things up such that you can use install.packages().

I also want to highlight that it doesn't feel super solid in my experimentation. I experienced several crashes of R along with the R LSP. I do think we should merge this to see how intermittent such problems are (and they may not be related directly) but I wanted to note what I was seeing!

Comment thread extensions/positron-r/package.nls.json Outdated
"r.configuration.interpreters.exclude.markdownDescription": "List of absolute paths to R binaries or folders containing R installations to exclude from the available R interpreters. These interpreters will not be displayed in the Positron UI.\n\nIf an interpreter is both included via `#positron.r.customRootFolders#` or `#positron.r.customBinaries#` and excluded via `#positron.r.interpreters.exclude#`, it will not be displayed in the Positron UI. See also `#positron.r.interpreters.override#`.\n\nExample: On Linux, add `/custom/location/R/4.3.0/bin/R` to exclude the specific binary, or `/custom/location` to exclude any R installations within the directory.\n\nRequires a restart to take effect.",
"r.configuration.interpreters.override.markdownDescription": "List of absolute paths to R binaries or folders containing R installations to override the list of available R interpreters. Only the interpreters found at the specified paths will be displayed in the Positron UI.\n\nThis setting takes precedence over the `#positron.r.customBinaries#`, `#positron.r.customRootFolders#`, and `#positron.r.interpreters.exclude#` settings.\n\nExample: On Linux or Mac, add `/custom/location/R/4.3.0/bin/R` to include only this specific installation, or `/custom/location` to include only R installations found within the directory.\n\nRequires a restart to take effect.",
"r.configuration.interpreters.default.markdownDescription": "Absolute path to the default R binary to use for new workspaces. This setting no longer applies once you select an R interpreter for the workspace.\n\nExample: On Linux, add `/custom/location/R/4.3.0/bin/R` to set the default interpreter to the specific R binary.\n\nRequires a restart to take effect.",
"r.configuration.interpreters.condaDiscovery.markdownDescription": "Enable discovery of R installations within conda/mamba environments. Support for conda environments in Positron is experimental and may not work correctly in all cases. When enabled, R installations found in conda environments will be available for selection, and the conda environment will be automatically activated when starting R to ensure compilation tools and dependencies are available.\n\nRequires a restart to take effect.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a claim about compilation tools? I still can't use install.packages() with this change and have to install packages via conda.

Also, I do think the suggestion from @jennybc to get more explicit here about "starting the R console" is probably a good idea.

@jmcphers jmcphers merged commit 6ec2be7 into main Dec 2, 2025
46 of 49 checks passed
@jmcphers jmcphers deleted the feature/conda-activate-for-r branch December 2, 2025 20:36
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants