Commit edfc2035 authored by Laurae's avatar Laurae Committed by Guolin Ke
Browse files

Instruction for R-package installation with precompiled dll/lib (#598)

* readme Helper package for R-package installation

* Fix code indentation bug

* Add warning about default compiler in Windows

* Avoid repeat

* Add Rtools requirement

* Wording to promote VS as default choice for user
parent 3a4608f4
......@@ -7,9 +7,11 @@ Installation
### Preparation
You need to install git and [cmake](https://cmake.org/) first.
The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. You also can use Rtools (default) or [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`.
The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. You also can use Rtools (default) or [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. For MinGW users who wants to install online, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)).
It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For simple systems (like laptops or small desktops), MinGW64 is recommended.
It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017).
For Windows users, installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory.
For Mac OS X users, gcc with OpenMP support must be installed first. Refer to [wiki](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx) for installing gcc with OpenMP support.
......@@ -43,6 +45,8 @@ You can also install directly from R using the repository with `devtools`:
devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
```
If you are using a precompiled dll/lib locally, you can move the dll/lib into LightGBM root folder, modify `LightGBM/R-package/src/install.libs.R`'s 2nd line (change `use_precompile <- FALSE` to `use_precompile <- TRUE`), and install R-package as usual.
When your package installation is done, you can check quickly if your LightGBM R package is working by running the following:
```r
......@@ -54,6 +58,43 @@ params <- list(objective="regression", metric="l2")
model <- lgb.cv(params, dtrain, 10, nfold=5, min_data=1, learning_rate=1, early_stopping_rounds=10)
```
Installation with precompiled dll/lib from R using GitHub
------------
You can install LightGBM R-package from GitHub with devtools thanks to a helper package for LightGBM.
### Prerequisites
You will need:
* Precompiled LightGBM dll/lib
* MinGW / Visual Studio / gcc (depending on your OS and your needs) with make in PATH environment variable
* git in PATH environment variable
* [cmake](https://cmake.org/) in PATH environment variable
* [lgbdl](https://github.com/Laurae2/lgbdl/) R-package, which can be installed using `devtools::install_github("Laurae2/lgbdl")`
* [Rtools](https://cran.r-project.org/bin/windows/Rtools/) if using Windows
Once you have all this setup, you can use `lgb.dl` from `lgbdl` package to install LightGBM from repository.
For instance, you can install the R package from LightGBM master commit of GitHub using the following from R:
```r
lgb.dl(commit = "master",
compiler = "gcc",
repo = "https://github.com/Microsoft/LightGBM",
cores = 4)
```
You may also install using a precompiled dll/lib using the following from R:
```r
lgb.dl(commit = "master",
libdll = "C:\\LightGBM\\windows\\x64\\DLL\\lib_lightgbm.dll", # YOUR PRECOMPILED DLL
repo = "https://github.com/Microsoft/LightGBM")
```
For more details about options, please check [Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/) R-package.
Examples
------------
......
......@@ -33,11 +33,12 @@ if (!use_precompile) {
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)
# Prepare installatio nsteps
# Prepare installation steps
cmake_cmd <- "cmake"
build_cmd <- "make -j"
lib_folder <- paste0(R_PACKAGE_SOURCE, "/src/")
# Check if Windows installation (for gcc vs Visual Studio)
if (WINDOWS) {
if (use_mingw) {
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment