Skip to content

Configuring a system to be able to build oce from source

Clark Richards edited this page Jan 6, 2016 · 15 revisions

Configuring R to build source packages differs between operating systems, and sometimes even with an operating system. This page is not meant to be a definitive resource, but describes the oce developers experience with setting up an R development environment on various systems.

1. Windows

Install R in the normal way, and then install Rtools. Done.

2. OSX

On OSX, it "just works", to use the Apple phrase ... except if you want to set up R to be able to build packages that require source code compilation, particularly if your package has fortran sources. The instructions below worked for me at one time.

2.1. Install XCode (i.e. Apple Developer tools)

Download XCode from the Mac App Store. After downloading and installing, install the Command Line Tools. Once Xcode is installed, the command-line tools can be installed by launching Xcode and following those steps:

Xcode > Preferences... > Downloads > Components Install the Command Line Tools package

It may be possible to install only the command line tools (without the full XCode download) using the following:

xcode-select --install

but I haven't tested this.

2.2. Install Git

I think it should be there after an XCode install (do which git to see), but if not go to: https://git-scm.com/

2.3. Install Latex

Easiest is to install MacTex. The MacTex download is quite large (several GBs). I'm sure it's possible to get away with the BasicTex installation, but I haven't tracked down what other extra LaTeX packages need to be installed to make building R packages work.

2.4. Install Gfortran

This is where things get tricky.

For the "Snow Leopard build of R" (see https://cran.rstudio.com/bin/macosx/), gfortran-4.2.3 is required. A binary installation package providing this is available at the R for Mac OSX tools page.

2.4.1 Mavericks R and gfortran-4.8.2

For the "Mavericks" version of R, gfortran-4.8.2 is required. Unfortunately there currently is not a nice pre-compiled installer available for it, and the first place to look (for a "new" OSX system) is

http://r.research.att.com/libs/

To install the gfortran binaries do:

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /

2.4.2 Mavericks R and gfortran-4.8.2 for core2 duo processors

However, for "older" processors, the above version of gfortran might not work, producing errors like:

gfortran-4.8   -fPIC  -g -O2  -c magdec.f -o magdec.o
gfortran-4.8: warning: couldn’t understand kern.osversion ‘14.5.0
f951: internal compiler error: Illegal instruction: 4
      
f951: internal compiler error: Abort trap: 6
gfortran-4.8: internal compiler error: Abort trap: 6 (program f951)

One option that has worked for me in the past is to install the "Mavericks" version of gfortran-4.8.2 from

https://gcc.gnu.org/wiki/GFortranBinaries#MacOS

but only after uninstalling any other gfortran binaries (perhaps using the gfortran-uninstall script in /usr/local/bin/. Then symlink /usr/local/bin/gfortran-4.8 to /usr/local/bin/gfortran:

sudo ln -s /usr/local/bin/gfortran /usr/local/bin/gfortran-4.8

For at least one very old system on which I tried this (a 13-inch Aluminum Late 2008 Macbook -- i.e. the oldest system that can actually run Mavericks/Yosemite/ElCapitan) the GNU gfortran binary did not work, as I still got errors like:

gfortran-4.8: warning: couldn’t understand kern.osversion ‘14.5.0
...
ld: library not found for -lgfortran

The only solution I found for that system was to install R (and all the associated tools) using Homebrew, which I do not recommend in general, because both I and Dan Kelley have had problems with Homebrew (and similar packaging systems for osx).

2.5 Install XQuartz

http://www.xquartz.org/

3. Linux

3.1 Easy installation

Just run

sudo apt-get install r-base

at a command prompt. This will install the version currently in the Ubuntu package repository, which will likely be at least one version older than the most recent.

3.2 Most recent version

The following instructions apply to installation of the latest version of R (3.2.3 as of the writing of this page) on a fresh installation of Linux Mint 17.2 (equivalent to Ubuntu 14:04 Trusty Tahr). These instructions are based on instructions found here.

Edit the /etc/apt/sources.list file to add an entry like:

deb https://<my.favorite.cran.mirror>/bin/linux/ubuntu trusty/

replacing <my.favorite.cran.mirror> with the CRAN mirror of your choice, e.g. https://cran.rstudio.com/.

Next, add the GPG key by doing

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9

To install the complete R system, use

sudo apt-get update
sudo apt-get install r-base

Users who need to compile R packages from source [e.g. package maintainers, or anyone installing packages with install.packages()] should also install the r-base-dev package:

sudo apt-get install r-base-dev

3.2 Other tools for Linux (texinfo, git, RStudio, etc)

To install packages that have vignettes, a LaTeX distribution will be required. Either install TexLive with

sudo apt-get install texlive

along with all the LaTeX package dependencies that might be required (grrr). Or build packages without vignettes, by doing

R CMD build --no-build-vignettes oce 

To install texinfo, do

sudo apt-get install texinfo

To install git, do

sudo apt-get install git

To install RStudio, download the latest package file from

https://www.rstudio.com/products/rstudio/download/

and install by running, e.g.

sudo dpkg -i rstudio-0.99.489-amd64.deb

or by clicking the package file to open the GUI-based installer.

Clone this wiki locally