Post

8 followers Follow
2
Avatar

system() call from RStudio does not find path; same command from commandline R works fine

I have a weird problem with the system() command when issued from within RStudio. The command works just fine if it is issued by R run with xemacs&ess, as well as command-line R. However, the exact same command does not work if I use RStudio.

Example:

system('fslview')
sh: fslview: command not found

Similar problem when I use the absolute path:

system('/usr/local/fsl/bin/fslview')
/usr/local/fsl/bin/fslview: line 6: /bin/fslview.app/Contents/MacOS/fslview: No such file or directory

Note the difference between the path in the system call, and the one returned in the error message.

Just to reiterate, this is not an issue of me using the wrong path, because the same command works from any other R prompt that is not mediated through RStudio, as well as from within the shell. Further, it is not a general issue with system(): the command:

system('ls')

works just fine even from within RStudio.

I have observed the same problem in mac OSX 10.7, 10.8, as well as in Ubuntu and other linux distributions.

Any help is greatly appreciated.

  • Tobias
Ian Pylvainen

12 comments

0
Avatar

I have this problem also on OSX 10.8 with Rstudio Version 0.98.475

sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics utils datasets grDevices methods

[7] base

other attached packages:
[1] bio3d_2.0

loaded via a namespace (and not attached):
[1] tools_3.0.2

Ian Pylvainen 0 votes
0
Avatar

Hi Barry,

In the meantime I was able to solve the problem. It turned out to be a path-issue after all… Here is the fix:

  • When in R, type Sys.getenv(‘R_HOME’) to find the path to R_ENVIRON file
  • cd to the directory and type “nano Renviron"
  • add the following line

FSL Setup

FSLDIR=/usr/local/fsl ## or wherever your fsl is installed
PATH=${FSLDIR}/bin/:$PATH
export FSLDIR PATH
. ${FSLDIR}/etc/fslconf/fsl.sh

Hope this helps.

Best,
Tobias

Ian Pylvainen 0 votes
0
Avatar

Hi Tobias,

Thanks for the update and we're glad you were able to figure it out. Let us know if anything else comes up.

Barry, let us know if Tobias's fix solves your problem or if you're still having issues.

Thanks,
Ian

Ian Pylvainen 0 votes
0
Avatar

Thanks for the reply Tobias.

I am on a mac and have no idea what fsl is never mind where it lives.
"which fsl" gives me nothing and I don't have an Renviron file in my /Library/Frameworks/R.framework/Resources as returned from Sys.getenv("R_HOME").

I am guessing you are trying to set $PATH, which I have in my ~/.profile. Is there a way to get Rstudio to just read this?

my system("echo $PATH") in Rstudio is diferent from that in regular R in the terminal.
Thanks!
Barry

Ian Pylvainen 0 votes
0
Avatar

Hi Barry,

Tobias was having the problem with the path occurring with the program 'fsl' - is there another program you're trying to use through the system() command that's not working? If so, can you check that program's path by running which <program-name> from the terminal?

Thanks,
Ian

Ian Pylvainen 0 votes
0
Avatar

Hi Ian,
I think its a $PATH not being set correctly issue as the system() calls I
am running are looking for exes that are not included in Rsudio's $PATH but
are in the regular R from the terminal E.g:

terminal

which muscle
/Users/barry/bin/muscle
echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/Users/barry/bin:/Users/barry/software/browndye_31jul12/bin:/opt/amber11/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin

In R from the terminal

system("muscle") # works great and system("echo $PATH") matches the
result above

However in Rstudio:

system("echo $PATH")
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin:/opt/local/bin
system("muscle")
sh: muscle: command not found

My $PATH is setup in my ~/.profile file. Can Rstudio not read this?
Thanks again,
B.

Ian Pylvainen 0 votes
2
Avatar

Hi Barry,

By default OSX GUI applications don't inherit the environment variables set in the .profile file. The easiest way to solve this is simply to invoke RStudio from the Terminal using the following command:

open -a RStudio

which will open it using the .profile settings you've configured on your machine.

Thanks for bringing this to our attention and it's something we'll be looking into in the future.

Ian

Ian Pylvainen 2 votes
2
Avatar

Has this issue been fixed yet? I'm running into this same problem. I'm using RStudio v0.98.1102 and I'm on Mac OS 10.10.2

Joshua Bradley 2 votes
0
Avatar

I'm am also still running into this same problem. I'm using RStudio Version 0.99.441 and I'm on Mac OS 10.10.3. Only the suggested workaround (start Rstudio from terminal) works for me.

cengel 0 votes
2
Avatar

Hello,

I have the same problem where R command-line reads on one PATH but RStudio reads a different one. 

I see this post if 2 years old but the version of RStudio I am running is still having the same issues. 

Is there an option in RStudio to specify where to read the $PATH within the .Renviron or .Rprofile? 

System specs:

MAC El Capitan 10.11.6

R version 3.4.0 (2017-04-21)

RStudio Version 1.0.143; 

 

Anna 2 votes