RStan Mac OS X Prerequisite Installation Instructions - PrinceWangR/rstan GitHub Wiki

This page describes the prerequisite installation procedure for RStan on Mac OS X.

Step 1. Install or Upgrade R

If you already have R installed to your liking, proceed to Step 2, Install C++ Toolchain.

Step 1.1: Check if R is already installed

  • Type command + space to open Spotlight.
  • In the upper right of your screen, where Spotlight opens, enter r into the search box.
  • If R does not pop up under "Applications" heading, you do not have R installed, and you should proceed to Step 1.3, Install R.
  • If R does pop up, click on R under "Applications" heading to open the R GUI and proceed to Step 1.2, Upgrade R.

Step 1.2: Upgrade R

  • Under the R menu item, click on Check for R Updates.
  • If the response after the prompt is "Your version of R is up to date", proceed to Step 2, Install C++ Toolchain.
  • These are very primitive instructions that require you to re-install all of your applications; suggestions for better approaches would be greatly appreciated (send to [email protected]):

Step 1.3: Install R

The rather terse official instructions on Installing R under OS X. This is an expanded version.

  • Go to the official Download R page.

  • Choose a mirror and click on it; you can go straight to the 0-cloud CRAN mirror, which is maintained by the RStudio project.

  • Click on the link under the bullet item Download R for (Mac) OS X.

  • Click on the link R-3.minor.patch.pkg (latest version) (for some value of minor.patch) to download the latest R package binary.

  • Navigate to the package download in the finder (available through the download link at the upper right of Safari), and click on the .pkg file.

  • Follow the instructions; all defaults are OK for RStan, but you probably want the GUI to make your life easier in the future for things like checking for updates.

  • Proceed to Step 2, Install C++ Toolchain.

Step 1.4 (Optional) Install RStudio

RStudio is an interactive development environment (IDE) for R.

  • Visit the RStudio Home Page
  • Navigate to the download page by clicking on the Download Now button.
  • Click on Download RStudio Desktop.
  • Click on the 64-bit Mac OS install link under the Recommended for Your System header to download the .dmg installer.
  • Double click on the downloaded RStudio .dmg file and follow the installation instructions.

The environment variable R_ARCH might not be set appropriately for versions earlier than 0.97.168. For version 0.97.168 or later, this step can be skipped (the safe way is to execute Sys.getenv('R_ARCH') and see if the result is not empty). For versions before 0.97.168, it must be set to one of the following values before installing and using Stan:

# for 64-bit RStudio 
> Sys.setenv(R_ARCH = '/x86_64')
# for 32-bit RStudio
> Sys.setenv(R_ARCH = '/i386')

If you are unsure whether to use the 32-bit or 64-bit configuration, execute the following in R:

> .Platform$r_arch

 

Step 2. Install C++ Toolchain

If you already have a C++ compiler and GNU-compatible version make installed that you are happy with, proceed to Install RStan.

The simplest way to install a complete C++ toolchain for Mac OS is to use an official Xcode release from Apple.

Step 2.1 Determine which version of OS X you are running

  • Click on Apple logo in upper left of your monitor.
  • Scroll down and click on the first menu item, About this Mac.
  • Read version number.

Step 2.2. Determine if you already have Xcode installed

  • Type command + space to open Spotlight.
  • In the upper right of your screen, where Spotlight opens, enter xcode into the search box.
  • If Xcode does not pop up under "Applications" heading, you do not have Xcode installed.
  • If Xcode does pop up under "Applications", make sure you have the latest version.
    • Click command + space to open Spotlight.
    • Enter enter app store into search box for Spotlight in upper right of your screen.
    • Click on App Store under Applications to open.
    • In App Store, click on Updates menu item (below blue downarrow).
    • If Xcode has an update, click to install.
  • Proceed to Install RStan.

Step 2.3. Install Xcode

For OS X 10.9 "Mavericks" or OS X 10.8 "Mountain Lion"
  • Open "App Store" application

  • Searach for 'xcode', choose Xcode, and follow its steps to install Xcode (using all default options is fine for Stan).

  • Open Xcode once to accept the license agreement

  • Proceed to Install RStan.

For OS X 10.7 "Lion" or Mac OS X 10.6 "Snow Leopard"

This is a much more involved process which requires you to register as an Apple Developer, find the appropriate version of Xcode and the Command-Line Tools, and install it.

  • If you are not registered as a developer, click on Register as an Apple Developer and follow the instructions to register; you will need an Apple ID.

  • Go to the Downloads Page for Developers

  • If you are not logged in to the Developer site with your Apple ID, do so.

  • Select the latest available version of Xcode and install it. For example, as of July 10, 2014, for "Lion", it is "Xcode 4.6.3". But for "Snow Leopard", it is "Xcode 3.2.6 and iOS SDK 4.3 for Snow Leopard".

  • Install command-line tools if they are not done with installing Xcode

    • check out if the command-line tools are available to R by using the following R code
    > system('clang++ -v')
    

    If the command-line tools are installed, the above command would print the version of clang C++ compiler. If not installed, the output from the above code looks like

    > system('clang++ -v')
    /bin/sh: clang++: command not found
    
    • install the command-line tools if they are not installed

    Go to the Downloads Page for Developers again. Find the latest "Command Line Tools" for your verion of Mac OS X. For example, for OS X Lion, it would be "Command Line Tools (OS X Lion) for Xcode - April 2013" (updated on July 10, 2014).