Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MatsSkoe

macrumors member
Original poster
I have a problem opening RStudio in Finder which does not occur when using Terminal with "open /Applications/RStudio.app/".

The origin of the problem is the need of a environment variable RSTUDIO_WHICH_R, which I set in .bash_profile. Somehow opening the application in Finder does not look into .bash_profile. Does anyone know a workaround?
 
How did you install RStudio and the R framework? Setting the environment variable is only necessary when you intend to override the default behaviour. If you installed R correctly, then this should work.
 
I have a problem opening RStudio in Finder which does not occur when using Terminal with "open /Applications/RStudio.app/".

The origin of the problem is the need of a environment variable RSTUDIO_WHICH_R, which I set in .bash_profile. Somehow opening the application in Finder does not look into .bash_profile. Does anyone know a workaround?
You could just make a little application launching app with AppleScript; this should work to apply the environment variable, although I don't have an app here to test. Open up AppleScript Editor in your Utilities folder and paste the following in:
Code:
do shell script "echo open /Applications/RStudio.app | /bin/bash"
Then save the script as an application and you can just double click on that to open Studio.
I don't use RStudio so I can't speak to whether you need to be using it this way.
 
  • Like
Reactions: Weaselboy
How did you install RStudio and the R framework? Setting the environment variable is only necessary when you intend to override the default behaviour. If you installed R correctly, then this should work.

I installed R with Anaconda (Python) so I can also use R with Jupyter Notebook. I don't want a double installation of R so I use "export RSTUDIO_WHICH_R="/Users/Mats/anaconda/bin/R"" and RStudio works opened from Terminal.
[doublepost=1460548314][/doublepost]
You could just make a little application launching app with AppleScript; this should work to apply the environment variable, although I don't have an app here to test. Open up AppleScript Editor in your Utilities folder and paste the following in:
Code:
do shell script "echo open /Applications/RStudio.app | /bin/bash"
Then save the script as an application and you can just double click on that to open Studio.
I don't use RStudio so I can't speak to whether you need to be using it this way.

Thank you for the suggestion. However, it does not work i'm afraid. I can always try Automater, I guess...
 
Have you considered symlinking /usr/local/bin/R to /Users/Mats/anaconda/bin/R?

Your solution is perfect in it simplicity. I knew of symbolic links but never needed to use them. RStudio does start normally this way, however in the same .bash_profile I specified the locale as
en_US.UTF-8. So I still have to open with Terminal do get normal functionality.
 
Makes sense that the dot files are not read, in that Finder process is a child of launchd, which is owned by root.

Along the lines of KALLT post above, can use launchctl to set environment variables for any GUI (Finder launched) program.

Code:
launchctl setenv var var_val

Can also add environment variable setting to /etc/launchd-user.conf

Along the lines of Automater, I have an old app I downloaded years ago called "AppFactory". Builds apps out of shell scripts. Don't need the app to accomplish this. Need to create an "app_name.app" folder, Contents folder under that. Under Contents, make a Resources folder and a MacOS folder. In MacOS, create your shell script to set environment variables and launch the app. chmod 775 shell_script_name. Done. Can now double click your homemade app and have everything setup correctly.
 
Along the lines of KALLT post above, can use launchctl to set environment variables for any GUI (Finder launched) program.

[…]

Can also add environment variable setting to /etc/launchd-user.conf

As of OS X Yosemite, launchd doesn't support configuration files.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.