Skip to content

Commit 58d4d47

Browse files
authored
Merge pull request #42 from curso-r/bugfix/CI
install pandoc in CI
2 parents 60aade5 + d294b0d commit 58d4d47

22 files changed

+65
-57
lines changed

.github/workflows/R-CMD-check.yaml

+17-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@ jobs:
1111
runs-on: windows-latest
1212
steps:
1313
- uses: actions/checkout@v2
14+
15+
- uses: r-lib/actions/setup-pandoc@v1
16+
1417
- uses: r-lib/actions/setup-r@master
18+
1519
- name: Install remotes
1620
run: install.packages(c("remotes", "rcmdcheck"))
1721
shell: Rscript {0}
18-
- name: Install catboost
22+
23+
- name: Install additional dependencies
1924
run: |
20-
remotes::install_url("https://github.com/catboost/catboost/releases/download/v0.23/catboost-R-Windows-0.23.tgz", INSTALL_opts = c("--no-multiarch"))
25+
remotes::install_deps(dependencies = TRUE, INSTALL_opts = c("--no-multiarch"))
2126
shell: Rscript {0}
22-
- name: Install dependencies
27+
28+
- name: Install catboost
2329
run: |
24-
remotes::install_deps(dependencies = TRUE, INSTALL_opts = c("--no-multiarch"))
30+
remotes::install_url("https://github.com/catboost/catboost/releases/download/v0.26/catboost-R-Windows-0.26.tgz", INSTALL_opts = c("--no-multiarch"))
2531
shell: Rscript {0}
32+
2633
- name: Check
27-
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--no-multiarch"), error_on = "error")
34+
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--no-multiarch"), error_on = "error", check_dir = "check")
2835
shell: Rscript {0}
36+
37+
- name: Show testthat output
38+
if: always()
39+
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
40+
shell: bash

DESCRIPTION

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Suggests:
2323
lightgbm,
2424
knitr,
2525
rmarkdown,
26-
readr
26+
readr,
27+
glue,
28+
scales
2729
RoxygenNote: 7.1.1
2830
Imports:
2931
rlang,

R/catboost.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ add_boost_tree_catboost <- function() {
191191
eng = "catboost",
192192
parsnip = "sample_prop",
193193
original = "subsample",
194-
func = list(pkg = "dials", fun = "sample_size"),
194+
func = list(pkg = "dials", fun = "sample_prop"),
195195
has_submodel = FALSE
196196
)
197197
}

R/lightgbm.R

+4-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ add_boost_tree_lightgbm <- function() {
168168
eng = "lightgbm",
169169
parsnip = "sample_prop",
170170
original = "bagging_fraction",
171-
func = list(pkg = "dials", fun = "sample_size"),
171+
func = list(pkg = "dials", fun = "sample_prop"),
172172
has_submodel = FALSE
173173
)
174174
}
@@ -272,7 +272,7 @@ train_lightgbm <- function(x, y, max_depth = 17, num_iterations = 10, learning_r
272272
data = prepare_df_lgbm(x),
273273
label = y,
274274
categorical_feature = categorical_columns(x),
275-
feature_pre_filter = FALSE
275+
params = list(feature_pre_filter = FALSE)
276276
)
277277

278278
main_args <- list(
@@ -345,7 +345,8 @@ predict_lightgbm_classification_raw <- function(object, new_data, ...) {
345345
#' @export
346346
predict_lightgbm_regression_numeric <- function(object, new_data, ...) {
347347
# train_colnames <- object$fit$.__enclos_env__$private$train_set$get_colnames()
348-
p <- stats::predict(object$fit, prepare_df_lgbm(new_data), reshape = TRUE, predict_disable_shape_check=TRUE, ...)
348+
p <- stats::predict(object$fit, prepare_df_lgbm(new_data), reshape = TRUE,
349+
params = list(predict_disable_shape_check=TRUE), ...)
349350
p
350351
}
351352

R/train.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
12
.onLoad <- function(libname, pkgname){
2-
add_decision_tree_tree()
3-
add_boost_tree_catboost()
4-
add_boost_tree_lightgbm()
3+
4+
if (!"lightgbm" %in% parsnip::get_model_env()$boost_tree$engine) {
5+
add_boost_tree_lightgbm()
6+
}
7+
8+
if (!"catboost" %in% parsnip::get_model_env()$boost_tree$engine) {
9+
add_boost_tree_catboost()
10+
}
11+
12+
if (!"tree" %in% parsnip::get_model_env()$decision_tree$engine) {
13+
add_decision_tree_tree()
14+
}
15+
516
}
617

718

R/tree.R

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ add_decision_tree_tree <- function() {
1212

1313
parsnip::set_dependency("decision_tree", eng = "tree", pkg = "tree")
1414

15+
parsnip::set_encoding(
16+
model = "decision_tree",
17+
eng = "tree",
18+
mode = "regression",
19+
options = list(
20+
predictor_indicators = "none",
21+
compute_intercept = FALSE,
22+
remove_intercept = FALSE,
23+
allow_sparse_x = FALSE
24+
)
25+
)
26+
1527
parsnip::set_fit(
1628
model = "decision_tree",
1729
eng = "tree",

tests/testthat/helper-model.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mtcars_class_binary$vs <- as.factor(mtcars$vs)
55

66
expect_all_modes_works <- function(model, engine) {
77
if(engine == "lightgbm") {
8-
model <- parsnip::set_engine(model, engine)
8+
model <- parsnip::set_engine(model, engine, verbose = -1L)
99
} else {
1010
model <- parsnip::set_engine(model, engine)
1111
}
@@ -92,6 +92,9 @@ expect_categorical_vars_works <- function(model) {
9292
}
9393

9494
expect_can_tune_boost_tree <- function(model) {
95+
96+
mtcars <- dplyr::sample_n(mtcars, size = 500, replace = TRUE)
97+
9598
mtcars$cyl <- factor(mtcars$cyl)
9699
mtcars$vs <- factor(mtcars$vs)
97100

tests/testthat/test-catboost.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ test_that('catboost alternate objective', {
1616
info <- catboost::catboost.get_model_params(cat_fit$fit)
1717

1818
expect_equal(info$loss_function$type, "Huber")
19-
expect_equal(info$loss_function$params[1], "delta")
20-
expect_equal(info$loss_function$params[2], "1")
19+
expect_true(grepl("delta", info$loss_function$params[1]))
20+
expect_equal(info$loss_function$params[[2]], "1")
2121
})
2222

2323
test_that("catboost with tune", {

tests/testthat/test-lightgbm.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_that("lightgbm mtry", {
5050

5151
test_that("lightgbm trees", {
5252

53-
hyperparameters <- data.frame(trees = c(1, 20, 300))
53+
hyperparameters <- data.frame(trees = c(1, 20, 50))
5454
for(i in 1:nrow(hyperparameters)) {
5555
model <- parsnip::boost_tree(trees = hyperparameters$trees[i], min_n = 1)
5656
expect_all_modes_works(model, 'lightgbm')

vignettes/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
*.html
22
*.R
3+
working-with-lightgbm-catboost_cache
4+
threading-forking-benchmark_cache
5+
parallel-processing_cache
6+
catboost_info

vignettes/parallel-processing_cache/html/__packages

-19
This file was deleted.

vignettes/parallel-processing_cache/html/code_fed05125bc1448aed90ee1abe24570d5.rdb

Whitespace-only changes.
Binary file not shown.

vignettes/parallel-processing_cache/html/forking_0880993d5c4023853d50944ad1d59fbe.rdb

Whitespace-only changes.
Binary file not shown.

vignettes/threading-forking-benchmark_cache/html/__packages

-19
This file was deleted.

vignettes/threading-forking-benchmark_cache/html/code_0f350d3724cc7b8a16bedcde1d89a6be.rdb

Whitespace-only changes.

vignettes/working-with-lightgbm-catboost.Rmd

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ knitr::opts_chunk$set(
1313
comment = "#>",
1414
eval = FALSE,
1515
warning = FALSE,
16-
message = FALSE
16+
message = FALSE,
17+
eval = FALSE
1718
)
1819
```
1920

2021
```{r setup}
2122
library(tidymodels)
2223
library(treesnip)
2324
data("diamonds", package = "ggplot2")
24-
25+
diamonds <- diamonds %>% sample_n(1000)
2526
# vfold resamples
2627
diamonds_splits <- vfold_cv(diamonds, v = 5)
2728
```

0 commit comments

Comments
 (0)