views:

512

answers:

2

Hi, I wrote some code in school to basically bring up different graphs from R and I had wanted to use it on a mac computer. Is there are way to use R terminal commands on a mac computer and is there a place where I could get more information about these mac R Terminal commands? Thanks so much!

+2  A: 

You can use the R command-line tools if you install R for Mac OS X. The R website has disk images with installers, or you can install via MacPorts, like this:

$ sudo port install R

The R website has a slightly later version (2.9.1) than MacPorts (which is at 2.8.1).

tgamblin
+2  A: 

I use the "R" command with the standard R.app GUI download, and would recommend using that instead of macports. After running the installer, I see:

$ which R
/usr/local/bin/R

$ ls -l /usr/local/bin/R
lrwxr-xr-x  1 root  wheel  47 Nov 12  2008 /usr/local/bin/R -> /Library/Frameworks/R.framework/Resources/bin/R

$ R
R version 2.8.0 (2008-10-20)
...
>

I actually prefer to use this rather than the GUI, because it uses the current working directory for the workspace and history files (.Rhistory and .RData). It makes it easier to organize projects in this way by filesystem directory, and is very natural if you're using the commandline for other tasks as well (like running data preprocessing scripts).

Also, the terminal version lets you more easily cancel an expensive computation by pressing Ctrl-C. The GUI sometimes locks up during these.

By default, I think Mac terminal R uses the X11 display system, which isn't as good as the Quartz one used by the GUI. You can change this though: get the CarbonEL package, then put the following into your ~/.Rprofile:

goquartz = function() {
  library("CarbonEL")
  options(device='quartz')
  Sys.unsetenv("DISPLAY")
}

if (.Platform$GUI == "X11") {
  # this means we're running in the terminal (not GUI) version.
  # if you actually want the X11 display, comment out the following line
  goquartz()
}
Brendan OConnor