Can you use R terminal commands on a Mac computer?

23,310

Solution 1

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()
}

Solution 2

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).

Share:
23,310
user130633
Author by

user130633

Updated on December 15, 2020

Comments

  • user130633
    user130633 over 3 years

    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?

  • Bilal Akil
    Bilal Akil almost 9 years
    Having trouble installing CarbonEL 6 years later... However I'm brand new to R, maybe it's easy but I dunno anything :(