Skip to content

Commit

Permalink
Merge pull request #108 from ModelOriented/cran_tests
Browse files Browse the repository at this point in the history
CRAN submission
  • Loading branch information
mayer79 authored Oct 14, 2023
2 parents 067fa82 + ebdc9db commit 8980218
Show file tree
Hide file tree
Showing 21 changed files with 503 additions and 377 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ examples.R
^pkgdown/_pkgdown\.yml$
^docs$
^pkgdown$
^revdep$
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 0.9.1
Date: 2023-07-18 17:24:12 UTC
SHA: 447cbcf8fca1601079604e015c68fb52171ae2ab
Version: 0.9.2
Date: 2023-10-14 16:44:29 UTC
SHA: 1d239694c309c6b48168b2ca19b8fd5c8d6f1d2d
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## Other changes

- Revised vignette on "mshapviz".
- Commenting out most unit tests as they would not pass timings measured on Debian.

# shapviz 0.9.1

Expand Down
4 changes: 2 additions & 2 deletions R/shapviz.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#'
#' SHAP values of dummy variables can be combined using the convenient
#' `collapse` argument.
#' Multi-output models created from XGBoost, LightGBM, {kernelshap}, or {permshap}
#' Multi-output models created from XGBoost, LightGBM, "kernelshap", or "permshap"
#' return a "mshapviz" object, containing a "shapviz" object per output.
#'
#' @inheritParams collapse_shap
Expand Down Expand Up @@ -130,7 +130,7 @@ shapviz.matrix = function(object, X, baseline = 0, collapse = NULL,
#' x <- shapviz(fit, X_pred = dtrain, X = iris)
#'
#' # Multiclass setting
#' params <- list(objective = "multi:softprob", num_class = 3, nthread = 1)
#' params <- list(objective = "multi:softprob", num_class = 3)
#' X_pred <- data.matrix(iris[, -5])
#' dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5]) - 1)
#' fit <- xgboost::xgb.train(params = params, data = dtrain, nrounds = 10)
Expand Down
2 changes: 1 addition & 1 deletion R/sv_importance.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @param bar_width Relative width of the bars (only used if bars are shown).
#' @param bar_type For "mshapviz" objects with `kind = "bar"`: How should bars be
#' represented? The default is "dodge" for dodged bars. Other options are "stack",
#' "wrap", or "separate" (via {patchwork}). Note that "separate" is currently
#' "wrap", or "separate" (via "patchwork"). Note that "separate" is currently
#' the only option that supports `show_numbers = TRUE`.
#' @param bee_width Relative width of the beeswarms.
#' @param bee_adjust Relative bandwidth adjustment factor used in
Expand Down
60 changes: 50 additions & 10 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,67 @@
# shapviz 0.9.1
# shapviz 0.9.2

## Resubmission 7

No effect of setDTthreads(2). Commenting out now all tests with xgboost.

## Resubmission 6

Test timing not fixed, still. Now testing to import {data.table} and setDTthreads(2) pre checks.

## Resubmission 5

Now trying

Sys.setenv(DT_NUM_THREADS = 1)
Sys.setenv("TESTTHAT_CPUS" = 1)
options(Ncpus = 1)


## Resubmission 4

Trying to set Sys.setenv(DT_NUM_THREADS = 2) in the unit tests to fix the crazy Debian behaviour.

## Resubmission 3

Moving one single nthread = 1 into param = list(). Setting nrounds = 1 in all tests. If this does not help, I will need to delete most unit tests.

## Resubmission 2

Setting nthread = 1 in unit tests and vignettes. Hope this fixes the problems.

## Resubmission 1

Fixing problems with curly braces in .rd files.

### Original message

Hello CRAN team

This is a small release fixing a future problem pointed out by Kurt Hornik about applying package_version() to numeric input.
{shapviz} already got 2 reverse dependencies, which look okay.

The update has mainly added more flexibility of the importance plots for multi-output models.

## Checks look good

### check(manual = TRUE, cran = TRUE)

- checking for future file timestamps ... NOTE
unable to verify current time

- checking HTML version of manual ... NOTE
Skipping checking HTML validation: no command 'tidy' found

### RHub
### RHub (usual notes)

debian ok

Others: hanging
* checking package dependencies ... NOTE
Packages which this enhances but not available for checking:
'fastshap', 'h2o', 'lightgbm'
* checking HTML version of manual ... NOTE
Skipping checking HTML validation: no command 'tidy' found
Skipping checking math rendering: package 'V8' unavailable

### Winbuilder()

Status: OK
R Under development (unstable) (2023-07-17 r84702 ucrt)

## Reverse dependencies (2)

- OK: 2
- BROKEN: 0
4 changes: 2 additions & 2 deletions man/shapviz.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sv_importance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions packaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use_package("ggfittext", "Imports", min_version = "0.8.0")
use_package("ggrepel", "Imports")
use_package("patchwork", "Imports")
use_package("xgboost", "Imports")
use_package("data.table", "Imports")

use_package("fastshap", "Enhances")
use_package("h2o", "Enhances")
Expand Down Expand Up @@ -93,6 +94,9 @@ use_github_links(overwrite = TRUE) # use this if this project is on github
# use_github_action("test-coverage")
# use_github_action("pkgdown")

# Revdep
use_revdep()

#=============================================================================
# Finish package building (can use fresh session)
#=============================================================================
Expand All @@ -102,16 +106,20 @@ library(devtools)
document()
test()
check(manual = TRUE, cran = TRUE, vignettes = FALSE)
build()
build(vignettes = FALSE)
# build(binary = TRUE)
install(upgrade = FALSE)

# Run only if package is public(!) and should go to CRAN
if (FALSE) {
check_win_devel()
check_rhub()
check_rhub(platforms = "debian-gcc-devel")

# Takes long
revdepcheck::revdep_check(num_workers = 4)

# Wait until above checks are passed without relevant notes/warnings
# then submit to CRAN
release()
devtools::release()
}
7 changes: 7 additions & 0 deletions revdep/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
checks
library
checks.noindex
library.noindex
cloud.noindex
data.sqlite
*.html
66 changes: 66 additions & 0 deletions revdep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Platform

|field |value |
|:--------|:--------------------------------------------------------|
|version |R version 4.3.0 (2023-04-21 ucrt) |
|os |Windows 11 x64 (build 22621) |
|system |x86_64, mingw32 |
|ui |RStudio |
|language |(EN) |
|collate |German_Switzerland.utf8 |
|ctype |German_Switzerland.utf8 |
|tz |Europe/Zurich |
|date |2023-10-13 |
|rstudio |2023.06.1+524 Mountain Hydrangea (desktop) |
|pandoc |3.1.6 @ C:\Users\Michael\AppData\Local\Pandoc\pandoc.exe |

# Dependencies

|package |old |new |Δ |
|:------------|:-------|:-------|:--|
|shapviz |0.9.1 |0.9.2 |* |
|cli |3.6.1 |3.6.1 | |
|colorspace |2.1-0 |2.1-0 | |
|commonmark |1.9.0 |1.9.0 | |
|curl |5.1.0 |5.1.0 | |
|data.table |1.14.8 |1.14.8 | |
|fansi |1.0.5 |1.0.5 | |
|farver |2.1.1 |2.1.1 | |
|ggfittext |0.10.1 |0.10.1 | |
|gggenes |0.5.1 |0.5.1 | |
|ggplot2 |3.4.4 |3.4.4 | |
|ggrepel |0.9.3 |0.9.3 | |
|glue |1.6.2 |1.6.2 | |
|gridtext |0.1.5 |0.1.5 | |
|gtable |0.3.4 |0.3.4 | |
|isoband |0.2.7 |0.2.7 | |
|jpeg |0.1-10 |0.1-10 | |
|jsonlite |1.8.7 |1.8.7 | |
|labeling |0.4.3 |0.4.3 | |
|lifecycle |1.0.3 |1.0.3 | |
|magrittr |2.0.3 |2.0.3 | |
|markdown |1.10 |1.10 | |
|munsell |0.5.0 |0.5.0 | |
|patchwork |1.1.3 |1.1.3 | |
|pillar |1.9.0 |1.9.0 | |
|pkgconfig |2.0.3 |2.0.3 | |
|png |0.1-8 |0.1-8 | |
|R6 |2.5.1 |2.5.1 | |
|RColorBrewer |1.1-3 |1.1-3 | |
|Rcpp |1.0.11 |1.0.11 | |
|rlang |1.1.1 |1.1.1 | |
|scales |1.2.1 |1.2.1 | |
|shades |1.4.0 |1.4.0 | |
|stringi |1.7.12 |1.7.12 | |
|stringr |1.5.0 |1.5.0 | |
|tibble |3.2.1 |3.2.1 | |
|utf8 |1.2.3 |1.2.3 | |
|vctrs |0.6.3 |0.6.3 | |
|viridisLite |0.4.2 |0.4.2 | |
|withr |2.5.1 |2.5.1 | |
|xfun |0.40 |0.40 | |
|xgboost |1.7.5.1 |1.7.5.1 | |
|xml2 |1.3.5 |1.3.5 | |

# Revdeps

7 changes: 7 additions & 0 deletions revdep/cran.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## revdepcheck results

We checked 2 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.

* We saw 0 new problems
* We failed to check 0 packages

1 change: 1 addition & 0 deletions revdep/failures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*Wow, no problems at all. :)*
1 change: 1 addition & 0 deletions revdep/problems.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*Wow, no problems at all. :)*
28 changes: 13 additions & 15 deletions tests/testthat/test-collapse_shap.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,16 @@ test_that("collapse_shap works for SHAP interactions and two collapses (result i
expect_equal(out, expected_value)
})

# Real data example
form <- Sepal.Length ~ Sepal.Width + Species - 1
iris_dummy <- model.matrix(form, data = iris)
dtrain <- xgboost::xgb.DMatrix(iris_dummy, label = iris[, 1L])
fit <- xgboost::xgb.train(data = dtrain, nrounds = 50L)
coll <- list(Species = paste0("Species", levels(iris$Species)))

test_that("Collapse works using XGB API", {
expect_no_error(
x <- shapviz(fit, X_pred = dtrain, X = iris, collapse = coll, interactions = TRUE)
)
expect_identical(colnames(x), c("Sepal.Width", "Species"))
})


# # Real data example
# form <- Sepal.Length ~ Sepal.Width + Species - 1
# iris_dummy <- model.matrix(form, data = iris)
# dtrain <- xgboost::xgb.DMatrix(iris_dummy, label = iris[, 1L])
# fit <- xgboost::xgb.train(params = list(nthread = 1L), data = dtrain, nrounds = 1L)
# coll <- list(Species = paste0("Species", levels(iris$Species)))
#
# test_that("Collapse works using XGB API", {
# expect_no_error(
# x <- shapviz(fit, X_pred = dtrain, X = iris, collapse = coll, interactions = TRUE)
# )
# expect_identical(colnames(x), c("Sepal.Width", "Species"))
# })
72 changes: 36 additions & 36 deletions tests/testthat/test-interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,39 +211,39 @@ test_that("mshapviz object contains original shapviz objects", {
expect_equal(mshp_inter[[2L]][1:nrow(shp_inter)], shp_inter)
})

# Multiclass with XGBoost
X_pred <- data.matrix(iris[, -5L])
dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5L]) - 1L)
fit <- xgboost::xgb.train(
data = dtrain,
nrounds = 50L,
nthread = 1L,
objective="multi:softprob",
num_class=3L
)
shp3 <- shapviz(fit, X_pred = X_pred, which_class = 3L, interactions = TRUE)
mshp <- shapviz(fit, X_pred = X_pred, interactions = TRUE)

test_that("is.shapviz() and is.mshapviz() functions work", {
expect_true(is.shapviz(shp3))
expect_true(is.mshapviz(mshp))
expect_false(is.shapviz(mshp))
expect_false(is.mshapviz(shp3))
})

test_that("shapviz on class 3 equals mshapviz[[3]] for classification", {
expect_equal(mshp[[3L]], shp3)
})

test_that("combining shapviz on classes 1, 2, 3 equal mshapviz", {
shp1 <- shapviz(fit, X_pred = X_pred, which_class = 1L, interactions = TRUE)
shp2 <- shapviz(fit, X_pred = X_pred, which_class = 2L, interactions = TRUE)
expect_equal(mshp, c(Class_1 = shp1, Class_2 = shp2, Class_3 = shp3))
expect_equal(mshp, mshapviz(list(Class_1 = shp1, Class_2 = shp2, Class_3 = shp3)))
})

test_that("combining non-shapviz objects fails", {
expect_error(c(shp3, 1))
expect_error(mshapviz(1, 2))
})

# # Multiclass with XGBoost
# X_pred <- data.matrix(iris[, -5L])
# dtrain <- xgboost::xgb.DMatrix(X_pred, label = as.integer(iris[, 5L]) - 1L)
# fit <- xgboost::xgb.train(
# params = list(nthread = 1L),
# data = dtrain,
# nrounds = 1L,
# objective="multi:softprob",
# num_class = 3L
# )
# shp3 <- shapviz(fit, X_pred = X_pred, which_class = 3L, interactions = TRUE)
# mshp <- shapviz(fit, X_pred = X_pred, interactions = TRUE)
#
# test_that("is.shapviz() and is.mshapviz() functions work", {
# expect_true(is.shapviz(shp3))
# expect_true(is.mshapviz(mshp))
# expect_false(is.shapviz(mshp))
# expect_false(is.mshapviz(shp3))
# })
#
# test_that("shapviz on class 3 equals mshapviz[[3]] for classification", {
# expect_equal(mshp[[3L]], shp3)
# })
#
# test_that("combining shapviz on classes 1, 2, 3 equal mshapviz", {
# shp1 <- shapviz(fit, X_pred = X_pred, which_class = 1L, interactions = TRUE)
# shp2 <- shapviz(fit, X_pred = X_pred, which_class = 2L, interactions = TRUE)
# expect_equal(mshp, c(Class_1 = shp1, Class_2 = shp2, Class_3 = shp3))
# expect_equal(mshp, mshapviz(list(Class_1 = shp1, Class_2 = shp2, Class_3 = shp3)))
# })
#
# test_that("combining non-shapviz objects fails", {
# expect_error(c(shp3, 1))
# expect_error(mshapviz(1, 2))
# })
#
Loading

0 comments on commit 8980218

Please sign in to comment.