Skip to content

Installing Pagoda2 for Mac OS

evanbiederstedt edited this page Feb 28, 2021 · 9 revisions

The package pagoda2 is currently on CRAN. We recommend that Mac OS users install via the binaries provided there, using the command:

install.packages('pagoda2')

This is the way we would recommend users install pagoda2.


Before pagoda2 was on CRAN, users had to install the package from source, either using

devtools::install_github('kharchenkolab/pagoda2')

or cloning the repo and installing via

git clone https://github.com/kharchenkolab/pagoda2.git
cd pagoda2
R CMD build .
R CMD install pagoda2*.tar.gz

When installing from source, the R package (with the associated C++ code) must compile locally. If you are a Mac OS X user, it's highly likely that you're using the gcc and clang built by Xcode. This results in some frustration for users trying to install pagoda2. For instance, Apple explicitly disabled OpenMP support in compilers that they ship in Xcode:

$ clang -c test_omp.c -fopenmp
clang: error: unsupported option '-fopenmp'

Note: OpenMP (Open Multi-Processing) is a library within pagoda2 which supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran.

There are some work arounds if you google solutions, e.g. this Stack Overflow post

Therefore, we recommend installing compilers and linking to them appropriately.

(This procedure has been tested on Mac OS Catalina, Version 10.15.5.)

Using Homebrew, install the following:

brew install gcc gfortran llvm libomp

Then, include the following in your ~/.zshrc (or ~/.bash_profile):

export PATH="/usr/local/opt/llvm/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"

Then, add the compiler paths to your ~/.R/Makevars file.

XCBASE:=$(shell xcrun --show-sdk-path)
LLVMBASE:=$(shell brew --prefix llvm)
GCCBASE:=$(shell brew --prefix gcc)
GETTEXT:=$(shell brew --prefix gettext)

CC=$(LLVMBASE)/bin/clang -fopenmp
CXX=$(LLVMBASE)/bin/clang++ -fopenmp
CXX11=$(LLVMBASE)/bin/clang++ -fopenmp
CXX14=$(LLVMBASE)/bin/clang++ -fopenmp
CXX17=$(LLVMBASE)/bin/clang++ -fopenmp
CXX1X=$(LLVMBASE)/bin/clang++ -fopenmp

CPPFLAGS=-isystem "$(LLVMBASE)/include" -isysroot "$(XCBASE)"
LDFLAGS=-L"$(LLVMBASE)/lib" -L"$(GETTEXT)/lib" --sysroot="$(XCBASE)"

FC=$(GCCBASE)/bin/gfortran -fopenmp
F77=$(GCCBASE)/bin/gfortran -fopenmp
FLIBS=-L$(GCCBASE)/lib/gcc/9/ -lm

(If you do not have a ~/.R/Makevars file, make one with mkdir .R; touch Makevars.)

Clone this wiki locally