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

RStudio IDE not loading PATH from shell #13341

Open
3 of 4 tasks
jabenninghoff opened this issue Jul 8, 2023 · 5 comments
Open
3 of 4 tasks

RStudio IDE not loading PATH from shell #13341

jabenninghoff opened this issue Jul 8, 2023 · 5 comments

Comments

@jabenninghoff
Copy link

jabenninghoff commented Jul 8, 2023

System details

RStudio Edition : Desktop
RStudio Version : 2023.06.1+524
OS Version      : macOS 13.4.1
R Version       : 4.3.1

Steps to reproduce the problem

  1. Install RStudio on a stock macOS Ventura (13.4.1) image
  2. Install a .zshrc that sets PATH, like this zshrc
  3. Launch RStudio using the GUI (Finder or Dock)

Describe the problem in detail

This issue is related to #10997 and #12529, but neither issue describes the whole problem in detail.

Looking at SessionPath.cpp:

  • The heuristic assumes that if /usr/local/bin is in PATH, RStudio was launched in a Terminal session. However, /usr/local/bin is in /etc/paths for every supported version of macOS, including Ventura. An alternative would be to look for /opt/homebrew/sbin or /usr/local/sbin (set by Homebrew in the shell, depending on architecture).
  • Even after removing /usr/local/bin from /etc/paths, the shell PATH is not loaded, even though grepl("(^|:)/usr/local/bin/?(:|$)", Sys.getenv("PATH")) evaluates to FALSE. I can't tell why this is, but Sys.getenv("SHELL") returns [1] "/bin/zsh" (the default shell on newer versions of macOS including Ventura)
  • It appears that initializePathViaShell is never called and PATH is set using initializePathViaEtcPaths
  • Finally, setting the path using PATH=$SHELL -l -c 'printf "%s" "$PATH"' generates a path that's different from what's in the Terminal (different order, doesn't include the full path)

To recap:

  1. Can the heuristic be changed to look for /opt/homebrew/sbin or /usr/local/sbin, or just load the shell PATH every time?
  2. Can the code be fixed so that initializePathViaShell is called on a factory fresh system?
  3. Can the -l flag be removed from the call to the shell in initializePathViaShell?

Default (factory fresh) /etc/paths:

/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin

Setting path using -l:

% PATH= $SHELL -l -c 'printf "%s" "$PATH"'
/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/quarto/bin:/Applications/Wireshark.app/Contents/MacOS:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin

Describe the behavior you expected

PATH set the same when RStudio is launched from either Terminal or GUI.

Launched via Terminal (open /Applications/Rstudio.app):

unlist(strsplit(Sys.getenv("PATH"), ":"))
#>  [1] "/Users/username/.pyenv/shims"                                                    
#>  [2] "/Users/username/.pyenv/bin"                                                      
#>  [3] "/Users/username/.rbenv/shims"                                                    
#>  [4] "/opt/homebrew/bin"                                                                
#>  [5] "/opt/homebrew/sbin"                                                               
#>  [6] "/usr/local/bin"                                                                   
#>  [7] "/usr/local/sbin"                                                                  
#>  [8] "/System/Cryptexes/App/usr/bin"                                                    
#>  [9] "/usr/bin"                                                                         
#> [10] "/bin"                                                                             
#> [11] "/usr/sbin"                                                                        
#> [12] "/sbin"                                                                            
#> [13] "/Applications/VMware Fusion.app/Contents/Public"                                  
#> [14] "/Library/TeX/texbin"                                                              
#> [15] "/opt/X11/bin"                                                                     
#> [16] "/Library/Apple/usr/bin"                                                           
#> [17] "/Applications/quarto/bin"                                                         
#> [18] "/Applications/Wireshark.app/Contents/MacOS"                                       
#> [19] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin"        
#> [20] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin"              
#> [21] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin"
#> [22] "/Applications/VMware Fusion.app/Contents/Library"                                 
#> [23] "/Library/Nessus/run/sbin"                                                         
#> [24] "/Users/username/bin"                                                             
#> [25] "/Users/username/go/bin"                                                          
#> [26] "/Users/username/Applications/quarto/bin"                                         
#> [27] "/usr/texbin"                                                                      
#> [28] "/Applications/RStudio.app/Contents/Resources/app/bin/postback"

Launched via GUI:

unlist(strsplit(Sys.getenv("PATH"), ":"))
#>  [1] "/usr/local/bin"                                                                   
#>  [2] "/System/Cryptexes/App/usr/bin"                                                    
#>  [3] "/usr/bin"                                                                         
#>  [4] "/bin"                                                                             
#>  [5] "/usr/sbin"                                                                        
#>  [6] "/sbin"                                                                            
#>  [7] "/Applications/VMware Fusion.app/Contents/Public"                                  
#>  [8] "/Library/TeX/texbin"                                                              
#>  [9] "/opt/X11/bin"                                                                     
#> [10] "/Library/Apple/usr/bin"                                                           
#> [11] "/Applications/quarto/bin"                                                         
#> [12] "/Applications/Wireshark.app/Contents/MacOS"                                       
#> [13] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin"        
#> [14] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin"              
#> [15] "/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin"
#> [16] "/Users/username/Applications/quarto/bin"                                         
#> [17] "/usr/texbin"                                                                      
#> [18] "/Applications/RStudio.app/Contents/Resources/app/bin/postback"
  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
@jabenninghoff jabenninghoff added bug new New incoming issues, ready for initial review. labels Jul 8, 2023
@ronblum
Copy link
Contributor

ronblum commented Jul 11, 2023

@jabenninghoff Thank you for raising the issue! Running RStudio from the GUI will only pick up global environment variables. To pick up the variables in .zshrc, you'd have to run RStudio from the terminal. This response addresses this: #6482 (comment)

However, I'll keep this open as an enhancement request to include /opt/homebrew/sbin or /usr/local/sbin (and possibly the other suggestions).

@ronblum ronblum added enhancement macos and removed new New incoming issues, ready for initial review. bug labels Jul 11, 2023
Copy link

github-actions bot commented Jan 8, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

@github-actions github-actions bot added the stale Issues which have been closed automatically due to inactivitiy. label Jan 8, 2024
@jabenninghoff
Copy link
Author

This is still an issue. Thanks.

@kevinushey
Copy link
Contributor

IMHO, if we want to solve this, we should just start running the R session through a shell, rather than launching it directly. Our attempts to manually set the PATH in the same way a shell might have led to other problems.

@kevinushey kevinushey removed the stale Issues which have been closed automatically due to inactivitiy. label Jan 8, 2024
@jabenninghoff
Copy link
Author

jabenninghoff commented Jan 8, 2024

IMHO, if we want to solve this, we should just start running the R session through a shell, rather than launching it directly. Our attempts to manually set the PATH in the same way a shell might have led to other problems.

That's what I've needed to use as a workaround (run open /Applications/RStudio.app in Terminal); I added a detection script to my .Rprofile to remind me to do so if it didn't discover pandoc in my PATH, so that change would solve the issue for me. Perhaps this could be a new setting in RStudio ("launch R session through shell") which would allow people to choose their preferred shell.

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

3 participants