Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-package] Add docs on building and using precompiled binaries for the R package #3285

Merged
merged 17 commits into from
Aug 12, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ LightGBM R-package
Installation
------------

### Installing Precompiled Binaries

Starting with `LightGBM` 3.0.0, precompiled binaries for the R package are created for each release. These packages do not require compilation, so they will be faster and easier to install than packages that are built from source. These packages are created with R 4.0 and are not guaranteed to work with other R versions.

Binaries are available for Windows, Mac, and Linux systems. They are not guaranteed to work with all variants and versions of these operating systems. Please [open an issue](https://github.com/microsoft/LightGBM/issues) if you encoutnter any problems.

To install a binary for the R package:

1. Choose a release from [the "Releases" page](https://github.com/microsoft/LightGBM/releases)
2. Choose a file based on your operating system. Right-click it and choose "copy link address"
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
3. Copy that link into `PKG_URL` in the code below and run it.

This sample code installs versioon 3.0.0-1 of the R package on Mac.

```r
PKG_URL <- "https://github.com/microsoft/LightGBM/releases/download/v3.0.0rc1/lightgbm_3.0.0-1-r40-macos.tgz"
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

local_file <- paste0("lightgbm.", tools::file_ext(PKG_URL))

download.file(
url = PKG_URL
, destfile = local_file
)
install.packages(
pkgs = local_file
, type = "binary"
, repos = NULL
)
```

### Preparation

You need to install git and [CMake](https://cmake.org/) first.
Expand Down Expand Up @@ -221,6 +251,73 @@ At build time, `configure.win` will be run and used to create a file `Makevars.w
1. Edit `configure.win` directly
2. Edit `src/Makevars.win.in`

### Build Precompiled Binaries of the CRAN Package

This section is mainly for maintainers. As long as the R package is not available on CRAN (which will build precompiled binaries automatically) you may want to build precompiled versions of the R package manually, since these will be easier for users to install.

For more details, see ["Writing R Extensions"](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Building-binary-packages).

Packages built like this will only work for the minor version of R used to build them. They may or may not work across different versions of operating systems
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

**Mac**

Binary produced: `lightgbm_${VERSION}-r40-macos.tgz`
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

```shell
LGB_VERSION="3.0.0-1"
sh build-cran-package.sh
R CMD INSTALL --build lightgbm_${LGB_VERSION}.tar.gz
mv \
lightgbm_${LGB_VERSION}.tgz \
lightgbm_${LGB_VERSION}-r40-macos.tgz
```

**Linux**

Binary produced: `lightgbm_${VERSION}-r40-linux.tar.gz`
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

You can access a Linux system that has R and its build toolchain installed with the `rocker` Docker images.

```shell
R_VERSION=4.0.2

docker run \
-v $(pwd):/opt/LightGBM \
-it rocker/verse:${R_VERSION} \
/bin/bash
```

From inside that container, the commands to create a precompiled binary are very similar
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

```shell
cd /opt/LightGBM
LGB_VERSION="3.0.0-1"
sh build-cran-package.sh
R CMD INSTALL --build lightgbm_${LGB_VERSION}.tar.gz
mv \
lightgbm_${LGB_VERSION}_R_*-linux-gnu.tar.gz \
lightgbm_${LGB_VERSION}-r40-linux.tgz
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
```

Exit the container, and the binary package should still be there on the host system.

```shell
exit
```

**Windows**

Binary produced: `lightgbm_${VERSION}.zip`
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

```shell
LGB_VERSION="3.0.0-1"
sh build-cran-package.sh
R CMD INSTALL --build lightgbm_${LGB_VERSION}.tar.gz
mv \
lightgbm_${LGB_VERSION}.tgz \
lightgbm_${LGB_VERSION}-r40-windows.tgz
```

External (Unofficial) Repositories
----------------------------------

Expand Down