0

The Problem: I do not find apps present in my bash path when using system() calls under 10.9 and using RStudio 0.98-501.

ex1

system("echo $PATH", intern=FALSE)
# this returns a very short PATH without any of my privately declared ones

ex2

system("bowtie --help", intern=TRUE)
# does not find bowtie while it is there all right and the same call works under R cli

This seems due to the fact that RStudio, being a GUI app, does not inherit the full PATH defined in my .profile/.bashrc

I found many posts related to this for older mac systems and assembled a solution working for mavericks. I tried the fix from Setting environment variables in OS X? but no success under mavericks.

launchctl setenv PATH $PATH
Community
  • 1
  • 1
splaisan
  • 845
  • 6
  • 22

1 Answers1

0

My solution: create a custom script/function and a custom path file

  • declare a custom function to be able to update it each time my PATH will change
  • store the function in a script to be able to run it as root
  • use this function to create a full equivalent of my PATH that OSX GUI apps (incl RStudio) will inherit

The function is declared in '.myfunctions' placed in my $HOME and sourced in my .profile

Now the script:

!/bin/bash

function setGUIpath () {
# create a custom path file in /etc/paths.d
# store the full PATH in that file for GUI apps
# created for the need to know PATH in RStudio system() calls

# mypath should exist and be writable (or sudo)
mypath=/etc/paths.d/mypath

# clear existing
cat /dev/null > ${mypath}

# fill with unique PATH items
# remove added 'PATH=' strings (what is doing this?)
echo $PATH | sed -e 's/PATH=//' | awk -F: '{for (i=1;i<=NF;i++) { if ( !x[$i]++ ) printf("%s\n",$i); }}' | sed -e 's/PATH=//' > ${mypath}

# restart Dock
osascript -e 'tell app "Dock" to quit'
}

# export it (optional?)
export -f setGUIpath

# run it
setGUIpath

Any comments or improvements are welcome if this presents any risk to my OS.

splaisan
  • 845
  • 6
  • 22