From 2a39b70acb9df4450a106bb4e99d4ebe5451623a Mon Sep 17 00:00:00 2001 From: Laurae Date: Sun, 23 Sep 2018 17:48:49 +0200 Subject: [PATCH] [R-package] Fix build_r.R failing in Windows (#1694) * Fix #1693 * Fix spacing * Fr -> For * Recursive causes error on strict R environments --- build_r.R | 75 +++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/build_r.R b/build_r.R index 63e222ea3ff..cc65f644cbe 100644 --- a/build_r.R +++ b/build_r.R @@ -1,4 +1,4 @@ -# 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) # 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 @@ -7,10 +7,10 @@ # R returns FALSE (not a non-zero exit code) if a file copy operation # breaks. Let's fix that -.handle_result <- function(res){ - if (!res){ - stop("Copying files failed!") - } +.handle_result <- function(res) { + if (!res) { + stop("Copying files failed!") + } } # Make a new temporary folder to work in @@ -18,65 +18,52 @@ unlink(x = "lightgbm_r", recursive = TRUE) dir.create("lightgbm_r") # copy in the relevant files -result <- file.copy( - from = "R-package/./" - , to = "lightgbm_r/" - , recursive = TRUE - , overwrite = TRUE -) +result <- file.copy(from = "R-package/./", + to = "lightgbm_r/", + recursive = TRUE, + overwrite = TRUE) .handle_result(result) -result <- file.copy( - from = "include/" - , to = file.path("lightgbm_r", "src/") - , recursive = TRUE - , overwrite = TRUE -) +result <- file.copy(from = "include/", + to = file.path("lightgbm_r", "src/"), + recursive = TRUE, + overwrite = TRUE) .handle_result(result) -result <- file.copy( - from = "src/" - , to = file.path("lightgbm_r", "src/") - , recursive = TRUE - , overwrite = TRUE -) +result <- file.copy(from = "src/", + to = file.path("lightgbm_r", "src/"), + recursive = TRUE, + overwrite = TRUE) .handle_result(result) -result <- file.copy( - from = "CMakeLists.txt" - , to = file.path("lightgbm_r", "inst", "bin/") - , recursive = TRUE - , overwrite = TRUE -) +result <- file.copy(from = "CMakeLists.txt", + to = file.path("lightgbm_r", "inst", "bin/"), + overwrite = TRUE) .handle_result(result) # rebuild documentation -devtools::document( - pkg = "lightgbm_r/" -) +devtools::document(pkg = "lightgbm_r") # Build the package # NOTE: --keep-empty-dirs is necessary to keep the deep paths expected # by CMake while also meeting the CRAN req to create object files # on demand -devtools::build( - pkg = "lightgbm_r" - , args = c("--keep-empty-dirs") -) +devtools::build(pkg = "lightgbm_r", + args = c("--keep-empty-dirs")) # Install the package version <- gsub( - "Version: " - , "" - , grep( - "Version: " - , readLines(con = file.path("lightgbm_r", "DESCRIPTION")) - , value = TRUE - ) + "Version: ", + "", + grep( + "Version: ", + readLines(con = file.path("lightgbm_r", "DESCRIPTION")), + value = TRUE + ) ) tarball <- file.path(getwd(), sprintf("lightgbm_%s.tar.gz", version)) system(sprintf("R CMD INSTALL %s --no-multi-arch", tarball)) # 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