Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use R terminal commands on a Mac computer?

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?

like image 873
user130633 Avatar asked Jul 15 '09 18:07

user130633


People also ask

Does R programming work on Mac?

There is only one version of R for macOS. However, R on macOS can be used either on the command-line as on other Unix systems, or via the R. APP GUI (see R. app).

How do you use Terminal commands on a Mac?

In the Terminal app on your Mac, press the Up Arrow key. The last command you entered appears on the command line. Continue pressing the Up Arrow key until you see the command you want, then press Return.

What is command option R on Mac?

Command (⌘)-R: Start up from the built-in macOS Recovery system. Or use Option-Command-R or Shift-Option-Command-R to start up from macOS Recovery over the internet. macOS Recovery installs different versions of macOS, depending on the key combination you use.


1 Answers

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()
}
like image 160
Brendan OConnor Avatar answered Sep 30 '22 01:09

Brendan OConnor