- [[r - datatable]]
# Problem
When loading data.table in R on macOS, I get this error:
```r
library(data.table)
# output below says using only 1 thread
data.table 1.14.8 using 1 threads (see ?getDTthreads). Latest news: r-datatable.com
**********
This installation of data.table has not detected OpenMP support. It should still work but in single-threaded mode.
This is a Mac. Please read https://mac.r-project.org/openmp/. Please engage with Apple and ask them for support. Check r-datatable.com for updates, and our Mac instructions here: https://github.com/Rdatatable/data.table/wiki/Installation. After several years of many reports of installation problems on Mac, it's time to gingerly point out that there have been no similar problems on Windows or Linux.
```
## Solution
- tested on Apple Silicon MacBook, macOS Ventura
- install homebrew if you have not already
- [Homebrew — The Missing Package Manager for macOS (or Linux)](https://brew.sh/)
- in bash, run `brew --version` to see if you already have homebrew installed; if yes, the output should be something like `Homebrew 4.0.28` (or some other version number)
```bash
# install homebrow if not already; see. https://brew.sh
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# update brew and install OpenMP runtime
brew update && brew install libomp
# install pkg-config
brew install pkg-config
# install xquartz
brew install xquartz --cask
# open the Makevars file in your home directory, `~/.R/Makevars`, and add the two lines below to the Makevars file; if you don't already have a Makevars file, then create it inside `~/.R` (see https://github.com/Rdatatable/data.table/issues/5419)
LDFLAGS += -L/opt/homebrew/opt/libomp/lib -lomp
CPPFLAGS += -I/opt/homebrew/opt/libomp/include -Xpreprocessor -fopenmp
```
### Testing the installation in R
```r
# install data.table from source
install.packages("data.table", type = "source")
library(data.table)
# output: using multiple threads
data.table 1.14.8 using 5 threads (see ?getDTthreads). Latest news: r-datatable.com
test.data.table() # should pass all tests!
```
# Resources
- Installation
- [Installation · Rdatatable/data.table Wiki · GitHub](https://github.com/Rdatatable/data.table/wiki/Installation)
- [Instructions for building from source for OpenMP support on Apple Silicon / M1 / arm64 under Monterey 12.4 · Issue #5419 · Rdatatable/data.table · GitHub](https://github.com/Rdatatable/data.table/issues/5419)
- By default, when does data.table use multiple threads?
- [Enforcing use of multithread (parallelize) when groupby · Issue #5200 · Rdatatable/data.table · GitHub](https://github.com/Rdatatable/data.table/issues/5200)
- [r - Parallelizing / Multithreading with data.table - Stack Overflow](https://stackoverflow.com/questions/69473020/parallelizing-multithreading-with-data-table)