Skip to content

Commit

Permalink
R-package version to 0.2 (#592)
Browse files Browse the repository at this point in the history
* Add some stuff for README

* Bump R package version and fix license

* Attempt to add one additional option and refactor

* Add more review fixes for install.libs.R

* Undo ./../../ removal (path breaking)

* Retry again simple /../

* No print, use cat.
  • Loading branch information
Laurae2 authored and guolinke committed Jun 6, 2017
1 parent bfdcdf6 commit 2c9ce59
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 72 deletions.
16 changes: 8 additions & 8 deletions R-package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Package: lightgbm
Type: Package
Title: Light Gradient Boosting Machine
Version: 0.1
Date: 2016-12-29
Version: 0.2
Date: 2017-06-05
Author: Guolin Ke <guolin.ke@microsoft.com>
Maintainer: Guolin Ke <guolin.ke@microsoft.com>
Description: LightGBM is a gradient boosting framework that uses tree based learning algorithms.
It is designed to be distributed and efficient with the following advantages:
1.Faster training speed and higher efficiency.
2.Lower memory usage.
3.Better accuracy.
4.Parallel learning supported.
5. Capable of handling large-scale data.
License: The MIT License (MIT) | file LICENSE
1. Faster training speed and higher efficiency.
2. Lower memory usage.
3. Better accuracy.
4. Parallel learning supported.
5. Capable of handling large-scale data.
License: MIT + file LICENSE
URL: https://github.com/Microsoft/LightGBM
BugReports: https://github.com/Microsoft/LightGBM/issues
VignetteBuilder: knitr
Expand Down
26 changes: 15 additions & 11 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,37 @@ Installation
------------

### Preparation
You need to install *git* and [cmake](https://cmake.org/) first.
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 MinGW64 to compile by set ```use_mingw <- TRUE``` in ```R-package/src/install.libs.R``` (We recommend *Visual Studio* for its better multi-threading efficency in Windows).
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 OSX user, gcc need to be installed first (refer to https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx).
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.

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.

To avoid critical package issues if you are using R 3.4.0 (not the patched/devel version), it is recommended to install once the LightGBM R package, even if it is an old version: `devtools::install_github("Microsoft/LightGBM@v1", subdir = "R-package")`. Make sure you have the correct permissions to install the package.

### Install
Install LightGBM R-package by following command:
Install LightGBM R-package with the following command:

```
```sh
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
R CMD INSTALL --build .
```
Or build a self-contained R package then install:
```

Or build a self-contained R package which can be installed afterwards:

```sh
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
Rscript build_package.R
R CMD INSTALL lightgbm_0.1.tar.gz
R CMD INSTALL lightgbm_0.2.tar.gz
```


Windows users may need to run with administrator rights (either R or the command prompt, depending on the way you are installing this package). Rtools must be installed for Windows. Linux users might require the appropriate user write permissions for packages.


Set ```use_gpu <- TRUE``` in ```R-package/src/install.libs.R``` can enable the build with GPU support (Need to install *Boost* and *OpenCL* first, details can be found in [gpu-support](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#with-gpu-support)).
Set `use_gpu` to `TRUE` in `R-package/src/install.libs.R` to enable the build with GPU support. You will need to install Boost and OpenCL first: details for installation can be found in [gpu-support](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#with-gpu-support).

You can also install directly from R using the repository with `devtools`:

Expand Down
20 changes: 10 additions & 10 deletions R-package/build_package.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
if(!file.copy("./../include", "src/", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/include")
if (!file.copy("./../include", "src/", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/include")
}
if(!file.copy("./../src", "src/", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/src")
if (!file.copy("./../src", "src/", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/src")
}
if(!file.copy("./../compute", "src/", overwrite=TRUE, recursive = TRUE)){
print("cannot find folder LightGBM/compute, will disable GPU build")
if (!file.copy("./../compute", "src/", overwrite = TRUE, recursive = TRUE)) {
print("Cannot find folder LightGBM/compute, will disable GPU build")
}
if(!file.copy("./../CMakeLists.txt", "src/", overwrite=TRUE, recursive=TRUE)){
stop("cannot find file LightGBM/CMakeLists.txt")
if (!file.copy("./../CMakeLists.txt", "src/", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find file LightGBM/CMakeLists.txt")
}
if(!file.exists("src/_IS_FULL_PACKAGE")){
if (!file.exists("src/_IS_FULL_PACKAGE")) {
file.create("src/_IS_FULL_PACKAGE")
}
system("R CMD build --no-build-vignettes .")
system("R CMD build --no-build-vignettes .")
113 changes: 70 additions & 43 deletions R-package/src/install.libs.R
Original file line number Diff line number Diff line change
@@ -1,56 +1,83 @@
# User options
use_precompile <- FALSE
use_gpu <- FALSE
use_mingw <- FALSE
source_dir <- paste0(R_PACKAGE_SOURCE, '/src')
setwd(source_dir)
if(!file.exists("_IS_FULL_PACKAGE")){
if(!file.copy("./../../include", "./", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/include")
}
if(!file.copy("./../../src", "./", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/src")

# Check for precompilation
if (!use_precompile) {

# Check repository content
source_dir <- paste0(R_PACKAGE_SOURCE, "/src")
setwd(source_dir)

if (!file.exists("_IS_FULL_PACKAGE")) {
if (!file.copy("./../../include", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/include")
}
if (!file.copy("./../../src", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find folder LightGBM/src")
}
if (use_gpu) {
if (!file.copy("./../../compute", "./", overwrite = TRUE, recursive = TRUE)) {
print("Cannot find folder LightGBM/compute, disabling GPU build.")
use_gpu <- FALSE
}
}
if (!file.copy("./../../CMakeLists.txt", "./", overwrite = TRUE, recursive = TRUE)) {
stop("Cannot find file LightGBM/CMakeLists.txt")
}
}
if(use_gpu){
if(!file.copy("./../../compute", "./", overwrite=TRUE, recursive = TRUE)){
print("cannot find folder LightGBM/compute, will disable GPU build")
use_gpu <- FALSE

# Prepare building package
build_dir <- paste0(source_dir, "/build")
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)

# Prepare installatio nsteps
cmake_cmd <- "cmake"
build_cmd <- "make -j"
lib_folder <- paste0(R_PACKAGE_SOURCE, "/src")

if (WINDOWS) {
if (use_mingw) {
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe -j"
} else {
cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- paste0(R_PACKAGE_SOURCE, "/src/Release")
}
}
if(!file.copy("./../../CMakeLists.txt", "./", overwrite=TRUE, recursive=TRUE)){
stop("cannot find file LightGBM/CMakeLists.txt")

if (use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
}
}

build_dir <- paste0(source_dir, "/build")
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)

cmake_cmd <- "cmake"
build_cmd <- "make -j"
lib_folder <- paste0(R_PACKAGE_SOURCE, '/src')

if (WINDOWS) {
if(use_mingw){
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe -j"
} else{
cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- paste0(R_PACKAGE_SOURCE, '/src/Release')

# Install
system(paste0(cmake_cmd, " .."))
system(build_cmd)
src <- paste0(lib_folder, "/lib_lightgbm", SHLIB_EXT)

} else {

# Has precompiled package
lib_folder <- paste0(R_PACKAGE_SOURCE, "/../")
if (file.exists(paste0(lib_folder, "lib_lightgbm", SHLIB_EXT))) {
src <- paste0(lib_folder, "lib_lightgbm", SHLIB_EXT)
} else if (file.exists(paste0(lib_folder, "windows/x64/DLL/lib_lightgbm", SHLIB_EXT))) {
src <- paste0(lib_folder, "windows/x64/DLL/lib_lightgbm", SHLIB_EXT)
} else {
src <- paste0(lib_folder, "Release/lib_lightgbm", SHLIB_EXT) # Expected result: installation will fail if it is not here or any other
}

}

if(use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
}

system(paste0(cmake_cmd, " .."))
system(build_cmd)
dest <- file.path(R_PACKAGE_DIR, paste0('libs', R_ARCH))
# Check installation correctness
dest <- file.path(R_PACKAGE_DIR, paste0("libs", R_ARCH))
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
src <- paste0(lib_folder, '/lib_lightgbm', SHLIB_EXT)
if(file.exists(src)){
print(paste0("find library file: ", src))
if (file.exists(src)) {
cat("Found library file: ", src, " to move to ", dest, sep = "")
file.copy(src, dest, overwrite = TRUE)
} else {
stop("cannot find lib_lightgbm.dll")
stop(paste0("Cannot find lib_lightgbm", SHLIB_EXT))
}

0 comments on commit 2c9ce59

Please sign in to comment.