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
这似乎是因为作为GUI应用程序的RStudio没有继承我的.profile / .bashrc中定义的完整PATH
我找到了许多与旧系统相关的帖子,并为小牛队组建了一个解决方案。我尝试了Setting environment variables in OS X?的修复,但在小牛队下没有成功。
launchctl setenv PATH $PATH
答案 0 :(得分:0)
该功能在' .myfunctions'中声明。放在我的$ HOME中并且来自我的.profile
现在脚本:
!/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
如果这对我的操作系统造成任何风险,欢迎提出任何意见或改进。