Commit 2a39b70a authored by Laurae's avatar Laurae Committed by James Lamb
Browse files

[R-package] Fix build_r.R failing in Windows (#1694)

* Fix #1693

* Fix spacing

* Fr -> For

* Recursive causes error on strict R environments
parent 577a03ce
# for macOS users who have decided to use gcc # For macOS users who have decided to use gcc
# (replace 8 with version of gcc installed on your machine) # (replace 8 with version of gcc installed on your machine)
# NOTE: your gcc / g++ from Homebrew is probably in /usr/local/bin # NOTE: your gcc / g++ from Homebrew is probably in /usr/local/bin
#export CXX=/usr/local/bin/g++-8 CC=/usr/local/bin/gcc-8 #export CXX=/usr/local/bin/g++-8 CC=/usr/local/bin/gcc-8
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
# R returns FALSE (not a non-zero exit code) if a file copy operation # R returns FALSE (not a non-zero exit code) if a file copy operation
# breaks. Let's fix that # breaks. Let's fix that
.handle_result <- function(res){ .handle_result <- function(res) {
if (!res){ if (!res) {
stop("Copying files failed!") stop("Copying files failed!")
} }
} }
# Make a new temporary folder to work in # Make a new temporary folder to work in
...@@ -18,65 +18,52 @@ unlink(x = "lightgbm_r", recursive = TRUE) ...@@ -18,65 +18,52 @@ unlink(x = "lightgbm_r", recursive = TRUE)
dir.create("lightgbm_r") dir.create("lightgbm_r")
# copy in the relevant files # copy in the relevant files
result <- file.copy( result <- file.copy(from = "R-package/./",
from = "R-package/./" to = "lightgbm_r/",
, to = "lightgbm_r/" recursive = TRUE,
, recursive = TRUE overwrite = TRUE)
, overwrite = TRUE
)
.handle_result(result) .handle_result(result)
result <- file.copy( result <- file.copy(from = "include/",
from = "include/" to = file.path("lightgbm_r", "src/"),
, to = file.path("lightgbm_r", "src/") recursive = TRUE,
, recursive = TRUE overwrite = TRUE)
, overwrite = TRUE
)
.handle_result(result) .handle_result(result)
result <- file.copy( result <- file.copy(from = "src/",
from = "src/" to = file.path("lightgbm_r", "src/"),
, to = file.path("lightgbm_r", "src/") recursive = TRUE,
, recursive = TRUE overwrite = TRUE)
, overwrite = TRUE
)
.handle_result(result) .handle_result(result)
result <- file.copy( result <- file.copy(from = "CMakeLists.txt",
from = "CMakeLists.txt" to = file.path("lightgbm_r", "inst", "bin/"),
, to = file.path("lightgbm_r", "inst", "bin/") overwrite = TRUE)
, recursive = TRUE
, overwrite = TRUE
)
.handle_result(result) .handle_result(result)
# rebuild documentation # rebuild documentation
devtools::document( devtools::document(pkg = "lightgbm_r")
pkg = "lightgbm_r/"
)
# Build the package # Build the package
# NOTE: --keep-empty-dirs is necessary to keep the deep paths expected # NOTE: --keep-empty-dirs is necessary to keep the deep paths expected
# by CMake while also meeting the CRAN req to create object files # by CMake while also meeting the CRAN req to create object files
# on demand # on demand
devtools::build( devtools::build(pkg = "lightgbm_r",
pkg = "lightgbm_r" args = c("--keep-empty-dirs"))
, args = c("--keep-empty-dirs")
)
# Install the package # Install the package
version <- gsub( version <- gsub(
"Version: " "Version: ",
, "" "",
, grep( grep(
"Version: " "Version: ",
, readLines(con = file.path("lightgbm_r", "DESCRIPTION")) readLines(con = file.path("lightgbm_r", "DESCRIPTION")),
, value = TRUE value = TRUE
) )
) )
tarball <- file.path(getwd(), sprintf("lightgbm_%s.tar.gz", version)) tarball <- file.path(getwd(), sprintf("lightgbm_%s.tar.gz", version))
system(sprintf("R CMD INSTALL %s --no-multi-arch", tarball)) system(sprintf("R CMD INSTALL %s --no-multi-arch", tarball))
# Run R CMD CHECK # Run R CMD CHECK
#R CMD CHECK lightgbm_2.1.2.tar.gz --as-cran | tee check.log | cat # R CMD CHECK lightgbm_2.1.2.tar.gz --as-cran | tee check.log | cat
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