0

I'm using Ubuntu 18.04, R 3.6.3, and a recent version of RStudio. I have an executable named brittany. When I run which brittany in a terminal, it is found. When I run R in a terminal and I type Sys.which("brittany"), it is found. But when I type Sys.which("brittany") in the RStudio console, it is not found. Why? The path of this file is /home/stla/.local/bin/brittany.

I've found a workaround: if I do a symbolic link to this file in a folder that does not contain a period in its path, the symbolic link is found and I can execute it. Looks like a RStudio bug.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • I think this might be a duplicate of https://stackoverflow.com/questions/16867720/rstudio-server-environment-variables-not-loading – IRTFM Sep 30 '20 at 00:07

1 Answers1

1

So the $PATH value for your shell is different (at start, or via your 'dot'-files) than it is for RStudio. And the result path reveals: /home/$USER/.local/bin is a private path, not a system path.

I think RStudio honors ~/bin so maybe create that and add a softlink.

On the other hand, on my machine (Ubuntu 20.04, R 4.0.2, RStudio 1.4.781) I see

R> system("echo $PATH")
/home/edd/.local/bin:/home/edd/bin:/usr/local/sbin:/usr/local/bin:\
/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:\
/usr/lib/rstudio/bin/postback
R>

and this is not a fluke of system() as Sys.getenv("PATH") shows the same.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks. Yeah this is what I did (the symbolic link in `~/bin`) and this works. But why the $PATH is not the same in RStudio than in R launched from a terminal? I don't get this point. – Stéphane Laurent Sep 29 '20 at 23:26
  • @StéphaneLaurent It has ever been the case that a bash console will report a different PATH than an R console. It's not an Rstudio invention. But it's probably also the case that an Rstudio instance will have a different PATH than a naked R console session. Refer to the `?Startup` page for the situation with an R console and to the Rstudio docs for that situation. If you want to see what has been said about this in the R vs bash case then review a few of the hits with https://markmail.org/search/?q=list%3Aorg.r-project.r-help+bash+profile+environment – IRTFM Sep 29 '20 at 23:58