Installing wholebrain on macOS

Since WholeBrain heavily relies on STAN for statistical computations the following instructions are somewhat adapted from the installation of rstan.

  1. Install or Upgrade R

  2. Install Xcode and its C++ Toolchain

    • 2.1 Determine which version of OS X you are running
    • 2.2. Determine if you already have Xcode installed
    • 2.3. Install Xcode
  3. Install STAN

    • 3.1 set the number of cores in Rs makevars
    • 3.2. Install Rstan from CRAN
  4. Install OpenCV

    • 4.1 Install via Homebrew (recommended)
    • 4.2. Install via macports


1. Install or Upgrade R

If you already have R installed to your liking, proceed to step 2.

1.1 Check if you have R installed on your Mac.

  • Open up spotlight by holding down both Cmd + spacebar.
  • Skärmavbild 2015-10-02 kl. 15.39.56
  • 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.


1.2: Check if you need to upgrade R

  • Next to the apple symbol in the top left part of the screen you'll find the R menu. Klick on R and under the R menu item, click on Check for R Updates.
  • Skärmavbild 2015-10-02 kl. 15.37.14
  • If the response after the prompt is "Your version of R is up to date", proceed to Step 2, Install C++ Toolchain.
  • To uninstall R, follow the official instructions, Uninstalling R under OS X. Note that if care is not taken in order to migrate all the installed R packages before you update R you will end up with a clean install of R and have to manually install all the previous packages you had installed.
  • Proceed to Install wholebrain for R.

1. 3. Install or Upgrade R

  • 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 and click on the .pkg file to start installation.
  • Proceed to Step 2, Install C++ Toolchain.

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 wholebrain on R.

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

  • 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.
      • Proceed to Step 2.3, Install Xcode.
    • 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 wholebrain for R.
  • 2.3. Install Xcode

    • For OS X 10.8 "Mountain Lion" and up
      • Open "App Store" application
      • Search for 'xcode', choose Xcode, and follow its steps to install Xcode (using all default options is fine for wholebrain).
      • Proceed to Install wholebrain for R.
    • For OS X 10.7 "Lion" or Mac OS X 10.6 "Snow Leopard"
    • Installing Xcode for Lion or Snow Leopard is a much more involved process compared to OSX 10.8 and above 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).

3.1. Install QuartzX11

In order to be able to render 3D brains you'll need XQuartz unless you already have it installed (apple use to bundle X11 but have sinced removed it).
Download here: and follow the instructions.

4.1. Install OpenCV

Easiest way to build OpenCV on Mac is to use homebrew. If you encounter problems it might be easier to just build form source using Cmake then use these instructions instead [LINK].

Open up the Terminal App () by searching for terminal in spotlight.

In the Terminal window check if you have homebrew installed by entering the following command and press return:

which brew

The following output means homebrew is installed:


If homebrew is not installed you either don't get anything as a response or you should get:

brew not found

Then install homebrew by opening up the terminal and run the following command:

#install Homebrew from terminal.
ruby -e "$(curl -fsSL"

Install OpenCV by typing in the following in the terminal and press return:

#install OpenCV 3.2 using homebrew.
brew tap homebrew/science
brew install pkg-config opencv3
brew link opencv3 --force

4.1. Install FFTW3

In terminal execute:

#install FFTW3
brew install fftw --enable-shared --enable-threads
brew link fftw --force

5.1. Install WholeBrain from R

Install wholebrain from R:

if (!require(devtools)) {

6.1. Run WholeBrain on a sample tile

Try running wholebrain from R:

filename<-system.file('sample_tiles/rabiesEGFP.tif', package='wholebrain')