All code for this document is located at here.

In this tutorial, we will go through the steps of installing ANTsR, including those for ITKR.

There are 2 options for installing ITKR and ANTsR: one is using devtools and the other is installing the binaries. We recommend installing the binary file of ITKR and using devtools to install ANTsR.

1 Option 1: Using Devtools

1.1 Install devtools

You must have devtools installed to install from GitHub.

packages = installed.packages()
packages = packages[, "Package"]
if (!"devtools" %in% packages) {
  install.packages("devtools")
}

Please refer to installing devtools for additional instructions or troubleshooting.

1.2 Mac OSX

You need to install Command Line Tools, aka the command line tools for Xcode, if you have not already. http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/ is a great tutorial how.

1.3 Windows

Although still untested there is a good tutorial on running FSL on Windows as well as ANTsR on Windows through Linux Subsystem.

1.4 cmake and git

ANTsR depends on ITKR, which states in the DESCRIPTION file:

OS_type: unix
SystemRequirements: cmake, git, clang (recommended)

so you must install git and cmake. Also, you must have a Unix-based system get these programs to work, so Windows users are out of luck. The continuing discussion will only support Linux variants and Mac OSX.

1.5 Setting the PATH

In either Linux or Mac OSX, there is a PATH “environment variable”. This tells your computer which folders to look in when you type in a command. For example, the cd command changes directories and the code (or compiled code) to do that is located in a folder. When you type cd, your computer looks (in order) in the folders specified in the PATH variable.

In a shell (discussed later), you can type

which cd

and find the executable that you are calling when you actually execute the cd command.

1.6 Testing if cmake and git are installed

Below are some instructions testing whether git and cmake are installed. If they are not installed, then there are instructions to install them.

1.6.1 Mac OSX

If you are on Mac OSX open up the Terminal and type

which cmake
which git

and if no paths are returned, then you don’t have these installed.

1.6.1.1 Installing Git

Please go to https://www.atlassian.com/git/tutorials/install-git/mac-os-x if you do not have git installed. It is a good and comprehensive tutorial on how to install git (but you may already have it installed).

1.6.1.2 Installing CMake

You can download CMake and you can download either the Binary (recommended) or the Source (more advanced, not covered here - see install instructions from CMake website).

After downloading the Binary, you will have the CMake application. If you use the dmg, you can drag and drop the application into the /Applications folder. If you use bash (I believe is the default), then open the Terminal, type vi ~/.bash_profile. This will open an editor (vi) and type the letter i, go to the bottom of the document, and copy and paste

export PATH=$PATH:/Applications/CMake.app/Contents/bin

to the bottom. To exit type ESC+:+wq. The ESC escapes anything you were doing (like inserting text), the colon is telling vi you’re in "Colon mode, the w means write the file, and q means quit. If you edited a file and don’t want to save changes, use :q! (quitting and not saving/writing).

1.6.2 Linux

You open up the Terminal and type :

which cmake
which git

and if no paths are returned, then you don’t have these installed.

1.6.2.1 Installing git

Depending on the variant of Linux you are on, the following commands should work:

sudo apt-get install git # ubuntu/debian
sudo yum install git # centos/fedora

1.6.2.2 Installing cmake

http://askubuntu.com/questions/610291/how-to-install-cmake-3-2-on-ubuntu-14-04 is a good discussion on how to install cmake on Ubuntu. https://help.directadmin.com/item.php?id=494 is a good discussion on how to install cmake on Centos (hint sudo yum install cmake).

1.7 Installing ITKR

You must install ITKR and ANTsR from R from a Terminal NOT from a GUI (RStudio/R application).

After devtools is installed, you can update ITKR:

source("https://neuroconductor.org/neurocLite.R")
neuroc_install("ITKR")

This will take a lot of time to compile and such.

1.8 Installing ANTsR

You must install ITKR and ANTsR from R from a Terminal NOT from a GUI (RStudio/R application).

If ITKR did not install, stop. Stop here. ANTsR cannot work without ITKR. If you think ITKR has a configuration problem and NOT a problem with your setup, you should open an issue and see if the authors would be able to fix it. Make sure you try the same steps on another machine (or virtual machine) before saying that something is “broken”.

Again, we can install ANTsR using `devtools:

source("https://neuroconductor.org/neurocLite.R")
neuroc_install("ANTsR")

This also will take a lot of time to compile.

1.9 Updating ANTsR

ANTsR takes a long time to compile and ITKR takes even longer. If you want to re-install or update ANTsR from GitHub, but not update any of the dependencies (including ITKR), then you should run:

source("https://neuroconductor.org/neurocLite.R")
neuroc_install("ANTsR", upgrade_dependencies = FALSE)

2 Option 2: Installing Binaries

If you go to the Release Page for ANTsR they have pre-built binary releases for different systems. If not specified, a .tgz should be the binary for the Mac OSX version and the .tar.gz should be that for a PC/Linux. You should check to see when the last release was made as some of these may be largely outdated, may not have the latest bug fixes, and may not be versioned corresponding to some common rules.

3 Troubleshooting errors

If you see the following error when installing ITKR:

./configure: line 26: cmake: command not found

guess what? cmake cannot be found. You either need to repeat the steps above or try to install ITKR using a Terminal (by calling R) instead of RStudio or the R application. This is due to some environment variables (not PATH though) not being available to those programs. Also, make sure you put export before PATH, and make sure PATH is not defined somewhere lower in the ~/.bash_profile and overwrites your changes.

You can see all of PATH by typing in the Terminal:

echo ${PATH}

3.1 RGL

One of the packages ANTsR suggests is rgl. For Mac OSX, this should be installed with the package if not already installed, which usually works OK. On some Linux variants like Ubuntu, the installation may fail.

If you have errors installing rgl, then according to a StackOverflow post, you can install using the following command:

sudo apt-get install r-cran-rgl