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

Working in R with a conda environment #1210

Closed
pschloss opened this issue Oct 4, 2022 · 3 comments
Closed

Working in R with a conda environment #1210

pschloss opened this issue Oct 4, 2022 · 3 comments

Comments

@pschloss
Copy link

pschloss commented Oct 4, 2022

I'm working in a different conda environment for each of my projects and would like to have R launch within the correct environment when I cmd-enter on a line of R code (I'm using Mac OS X) so that I can use the R version and packages I have in my environment. I have figured out that if I install Microsoft's Python Extension and put ...

{
  "python.defaultInterpreterPath": "~/opt/miniconda3/envs/env-01/"
}

in {workspace-directory}/.vscode/settings.json then when I start a new bash terminal, the first command it will run is conda activate env-01. Unfortunately, when I do this with R code (e.g. 2+2) in a file (e.g. practice.R), it launches a new terminal and the first R command it tries to run is conda activate env-01 followed by 2+2.

Here's what the output to the terminal looks like:

conda activate env-01
2+2

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> conda activate env-01
Error: unexpected symbol in "conda activate"
> 2+2
[1] 4

I'm not really excited about adding "r.alwaysUseActiveTerminal": true to my settings.json file (as suggested here) since I like the flexibility of being able to "just" create the R terminal by doing cmd-enter.

It seems like there should be a way to automatically run the conda activate <environment_name> before launching R for the first time when doing cmd-enter on a chunk of R code. Is there a setting I'm missing or would this be something that could easily be fixed?

@pschloss pschloss added the bug label Oct 4, 2022
@ElianHugh
Copy link
Collaborator

Hi @pschloss ,

This is something that should be fixed by #1143 soon

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Oct 5, 2023
@github-actions
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

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

No branches or pull requests

2 participants