Vanderlei Debastiani
Vanderlei Debastiani

Reputation: 31

Shell PATH to R under macOS Big Sur

I have a problem with R CMD under Big Sur. I installed R via default .pkg (not via brew) and I have been using zsh (Z shell) as the default shell. I think that I have a problem with PATH that I am not able to fix.

In Terminal:

~ echo $0  
zsh  
~ echo $PATH             
/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Users/vanderleidebastiani/.jenv/bin:/opt/miniconda3/bin:/opt/miniconda3/condabin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Library/Frameworks/R.framework/Resources:/Library/Frameworks/R.framework/Resources  
~ R CMD  
looks ok  

In R/RStudio:

> system("echo $0")
sh
> system("echo $PATH")  
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/opt/local/bin:/Applications/RStudio.app/Contents/MacOS/postback  
> system("R CMD")  
sh: R: command not found
Warning message:
In system("R CMD") : error in running command

I can solve this temporarily with Sys.getenv if I include the PATH to "/Library/Frameworks/R.framework/Resources"

Sys.getenv("PATH")  
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/opt/local/bin:/Applications/RStudio.app/Contents/MacOS/postback" 
 
Sys.setenv(PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/opt/local/bin:/Applications/RStudio.app/Contents/MacOS/postback:/Library/Frameworks/R.framework/Resources")  

system("R CMD")  
-looks ok

I tried to include the PATH permanently, so I edited .bash_profile, .profile, .zshrc, .bashrc in my home folder (in case "/Users/vanderleidebastiani") to include:

# Setting PATH for R
export PATH="$PATH:/Library/Frameworks/R.framework/Resources"

However, it does not make any effect. The PATH does not recognize after I restart R, it goes back to initial settings.

Do I need to include PATH in another file or I made some mistake in the way to include it?

Best, Vanderlei

Upvotes: 3

Views: 8487

Answers (2)

Nate
Nate

Reputation: 21

I had the same problem but with access to homebrew installed binaries. The fix I found was to modify the global PATH variable in Big Sur.

It turns out if you drop a text file into the /etc/paths.d folder it will be parsed and added to PATH even after a restart of RStudio.

I used sudo nano /etc/paths.d/homebrew to add a text file and pasted in /opt/homebrew/bin and /opt/homebrew/sbin on separate lines. After saving and closing I rebooted RStudio and ran echo $PATH from RStudio's terminal to check that the path had been imported correctly.

Ref: https://serverfault.com/questions/16355/how-do-i-set-the-global-path-environment-variable-on-os-x

Upvotes: 0

Mauricio Silvestre
Mauricio Silvestre

Reputation: 311

To create a new path just do this in MACOS Big Sur

  1. sudo touch ~/.zshrc
  2. sudo nano export PATH=$PATH:/YOUR PATH
  3. crtl + x and save
  4. source ~/.zshrc or close and open the terminal

Check with echo $PATH

Upvotes: 7

Related Questions