1

Why does this happen?

Inside RStudio's R console:

> system("conda --info")
sh: conda: command not found
Warning message:
In system("conda --info") : error in running command

But the MacBook terminal sees it:

(base) 192:~ avoda$ conda --version
conda 4.10.3

So I tried checking whether the R available in terminal saw conda and it does:

(base) 192:~ avoda$ R

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (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.

[Previously saved workspace restored]

> system("conda --version")
conda 4.10.3
>

So the terminal and terminal-R see conda, but RStudio's R does not. Why does that happen?

PS: Terminal-R and RStudio-console-R seem to be the same R-software version (4.1.0), but have different environments?

  • Seems similar to this: https://community.rstudio.com/t/conda-command-not-found-in-rstudio-terminal/64565 – Alexandru-Ioan Voda Jan 24 '22 at 22:23
  • Compare `Sys.getenv("PATH")` (in R) with `echo "${PATH}"` (on the terminal). In the short-term, you can modify the `PATH` that R is seeing *in this process* by using `Sys.setenv(PATH=...)`, extending the existing PATH with where you know conda to be installed, using the appropriate os-specific separator. In the medium-term, you can add it via `~/.Renviron` or `~/.Rprofile`, but really this is a `PATH` issue that needs to be fixed at the shell or OS levels. – r2evans Jan 25 '22 at 01:52
  • See [this](https://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#I-get-_0060_0060command-not-found_0027_0027-in-the-GUI-yet-it-works-in-the-Terminal-_002d_002d-why_003f) section of the R for macOS FAQ. When started from a shell, R inherits `PATH` from that shell. That is not the case when R is started via a GUI like RStudio. – Mikael Jagan Jan 25 '22 at 03:40
  • @r2evans It's not a shell or OS issue, _per se_. It's really a GUI issue, and setting `PATH` in `~/.Renviron` or `~/.Rprofile` _is_ the recommended solution. – Mikael Jagan Jan 25 '22 at 03:50
  • I understand that it fixes this issue, but ... if R and RStudio are not seeing the correct `PATH`, then it is arguable that something is misconfigured in the user's environment. In my use-case (and therefore my assumption), R is not the only mechanism through which I access python, so fixing it in R alone is just half the battle. I recognize I may be in the minority here, but that's why I suggested that it may be better to set that at a grander level. YMMV, thanks. – r2evans Jan 25 '22 at 03:55
  • I see your point about RStudio *not* inheriting `PATH` ... that seems like a completely broken thing, not sure why that's preferred ... but since I don't use RStudio (I use emacs/ess), I don't have much game in that fight. – r2evans Jan 25 '22 at 03:57
  • 1
    @r2evans That makes sense - thanks for clarifying. In that case, the OP can modify the global default `PATH` by placing a text file containing the path to `conda` in the system directory `/etc/paths.d/` (example [here](https://serverfault.com/questions/16355/how-do-i-set-the-global-path-environment-variable-on-os-x)). That would affect _all_ applications, started with or without a shell, including RStudio. – Mikael Jagan Jan 25 '22 at 06:36
  • This is what I do: https://stackoverflow.com/a/62737170/570918 – merv Jan 25 '22 at 20:57

1 Answers1

0

Conda gets added to the user's interactive shell dynamically, but RStudio's default configuration is an non-login shell (e.g., /bin/bash or /bin/zsh).

Go to the RStudio settings Tools > Terminal > Terminal options..., change it to use a custom shell /bin/bash or /bin/zsh, and then add to Custom shell command-line options: a -l or -i, respectively. Something like:

enter image description here

This will launch into base (assuming auto-activate is on), but conda will at least be available.

merv
  • 67,214
  • 13
  • 180
  • 245