vignettes/Installation_and_configuration.Rmd
Installation_and_configuration.Rmd
There are two ways to install the ngme2
package:
Pre-built binaries are available for Windows and macOS with R versions 4.2, 4.3, 4.4, and 4.5. This is the recommended installation method as it avoids compilation issues, especially on macOS where OpenMP configuration can be challenging.
# Install ngme2 package from pre-built binaries
install.packages("ngme2",
repos = "https://davidbolin.github.io/ngme2/.binaries",
type = "binary")
The installation process will automatically detect your R version and operating system, and install the appropriate binary package.
You can also use this convenience function to handle the installation:
# Function to install the appropriate ngme2 binary
install_ngme2 <- function() {
# Detect R version
r_version <- paste(R.version$major, strsplit(R.version$minor, ".", fixed=TRUE)[[1]][1], sep=".")
# Detect system
system_type <- Sys.info()["sysname"]
# Check if the detected R version is supported
supported_versions <- c("4.2", "4.3", "4.4", "4.5")
if(!r_version %in% supported_versions) {
warning("Your R version (", r_version, ") may not have a pre-built binary. ",
"Trying the closest version or falling back to source installation.")
# Find the closest version
r_num <- as.numeric(r_version)
closest_version <- supported_versions[which.min(abs(as.numeric(supported_versions) - r_num))]
r_version <- closest_version
}
message("Installing ngme2 for R ", r_version, " from repository")
# Install the package
install.packages("ngme2",
repos = "https://davidbolin.github.io/ngme2/.binaries",
type = "binary")
}
# Run the function to install
install_ngme2()
If you prefer to install from source, or if pre-built binaries are not available for your platform or R version, you can install directly from GitHub:
remotes::install_github("davidbolin/ngme2", ref = "devel")
Note: Installing from source requires appropriate C++ compilers and OpenMP support. This can be complex, particularly on macOS. See the platform-specific instructions below if you encounter issues.
If you need to install from source, follow these platform-specific instructions:
For Mac OS X, the default C++ compiler does not support OpenMP, which
is required for multi-threading in ngme2
.
➜ clang -fopenmp hello.cpp
clang: error: unsupported option '-fopenmp'
To enable OpenMP on macOS:
~/.R/Makevars
(use
this exact configuration):# Use Homebrew LLVM's clang compiler (supports OpenMP)
CC=/opt/homebrew/opt/llvm@18/bin/clang
CXX=/opt/homebrew/opt/llvm@18/bin/clang++
CXX11=/opt/homebrew/opt/llvm@18/bin/clang++
CXX14=/opt/homebrew/opt/llvm@18/bin/clang++
CXX17=/opt/homebrew/opt/llvm@18/bin/clang++
CXX20=/opt/homebrew/opt/llvm@18/bin/clang++
# Add OpenMP flags
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
# Include and library paths for LLVM and OpenMP
CFLAGS += -I/opt/homebrew/opt/llvm@18/include -I/opt/homebrew/opt/libomp/include
CXXFLAGS += -I/opt/homebrew/opt/llvm@18/include -I/opt/homebrew/opt/libomp/include
LDFLAGS += -L/opt/homebrew/opt/llvm@18/lib -L/opt/homebrew/opt/llvm@18/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm@18/lib/c++ -L/opt/homebrew/opt/libomp/lib
FLIBS = -L/opt/homebrew/lib/gcc/current -lgfortran -lquadmath
Note: - The paths shown are for Apple Silicon Macs (M1/M2/M3). If
you’re using an Intel Mac, replace /opt/homebrew/
with
/usr/local/
. - It’s critical to use LLVM version 18
specifically due to compatibility issues with R’s OpenMP implementation
and newer LLVM versions.
remotes::install_github("davidbolin/ngme2", ref = "devel")
Most Linux distributions come with GCC/G++ compilers that already support OpenMP. If not, you can install the development tools package for your distribution.
For Debian/Ubuntu-based systems:
sudo apt-get update
sudo apt-get install r-base-dev build-essential libopenblas-dev liblapack-dev gfortran
For Red Hat/Fedora-based systems:
# From within R
install.packages("remotes")
remotes::install_github("davidbolin/ngme2", ref = "devel")
Windows installation from source is generally simpler as the standard R tools for Windows already include appropriate C++ compilers with OpenMP support.
Download and install the version of Rtools that corresponds to your R version from: https://cran.r-project.org/bin/windows/Rtools/
For R 4.0.0 and newer, use Rtools40 or newer.
During installation: - Make sure to select the option to add Rtools to your system PATH - Install the toolchain components
# From within R
install.packages("remotes")
remotes::install_github("davidbolin/ngme2", ref = "devel")
To verify that OpenMP is working correctly with ngme2
,
you can run a simple test:
~/.R/Makevars
configuration.LDFLAGS
.