Installing pre-packaged version
You can install xgboost from CRAN just like any other R package:
install.packages("xgboost")
Or you can install it from our weekly updated drat repo:
install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc")
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
For OSX users, single threaded version will be installed. To install multi-threaded version,
first follow Building on OSX to get the OpenMP enabled compiler. Then
Set the Makevars
file in highest piority for R.
The point is, there are three Makevars
: ~/.R/Makevars
, xgboost/R-package/src/Makevars
, and /usr/local/Cellar/r/3.2.0/R.framework/Resources/etc/Makeconf
(the last one obtained by running file.path(R.home("etc"), "Makeconf")
in R), and SHLIB_OPENMP_CXXFLAGS
is not set by default!! After trying, it seems that the first one has highest piority (surprise!).
Then inside R, run
install.packages("drat", repos="https://cran.rstudio.com")
drat:::addRepo("dmlc")
install.packages("xgboost", repos="http://dmlc.ml/drat/", type = "source")
Installing the development version
Make sure you have installed git and a recent C++ compiler supporting C++11 (e.g., g++-4.8 or higher).
On Windows, Rtools must be installed, and its bin directory has to be added to PATH during the installation.
And see the previous subsection for an OSX tip.
Due to the use of git-submodules, devtools::install_github
can no longer be used to install the latest version of R package.
Thus, one has to run git to check out the code first:
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
git submodule init
git submodule update
cd R-package
R CMD INSTALL .
If the last line fails because of the error R: command not found
, it means that R was not set up to run from command line.
In this case, just start R as you would normally do and run the following:
setwd('wherever/you/cloned/it/xgboost/R-package/')
install.packages('.', repos = NULL, type="source")
The package could also be built and installed with cmake (and Visual C++ 2015 on Windows) using instructions from the next section, but without GPU support (omit the -DUSE_CUDA=ON
cmake parameter).
If all fails, try Building the shared library to see whether a problem is specific to R package or not.
Installing R package with GPU support
The procedure and requirements are similar as in Building with GPU support, so make sure to read it first.
On Linux, starting from the XGBoost directory type:
mkdir build
cd build
cmake .. -DUSE_CUDA=ON -DR_LIB=ON
make install -j
When default target is used, an R package shared library would be built in the build
area.
The install
target, in addition, assembles the package files with this shared library under build/R-package
, and runs R CMD INSTALL
.
On Windows, cmake with Visual C++ Build Tools (or Visual Studio) has to be used to build an R package with GPU support. Rtools must also be installed (perhaps, some other MinGW distributions with gendef.exe
and dlltool.exe
would work, but that was not tested).
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DUSE_CUDA=ON -DR_LIB=ON
cmake --build . --target install --config Release
When --target xgboost
is used, an R package dll would be built under build/Release
.
The --target install
, in addition, assembles the package files with this dll under build/R-package
, and runs R CMD INSTALL
.
If cmake can’t find your R during the configuration step, you might provide the location of its executable to cmake like this: -DLIBR_EXECUTABLE="C:/Program Files/R/R-3.4.1/bin/x64/R.exe"
.
If on Windows you get a “permission denied” error when trying to write to …Program Files/R/… during the package installation, create a .Rprofile
file in your personal home directory (if you don’t already have one in there), and add a line to it which specifies the location of your R packages user library, like the following:
.libPaths( unique(c("C:/Users/USERNAME/Documents/R/win-library/3.4", .libPaths())))
You might find the exact location by running .libPaths()
in R GUI or RStudio.