Skip to content

Commit 27ddc0c

Browse files
authored
Merge pull request #175 from ModelOriented/simplify-dep2d
Simplify sv_dependence2D code
2 parents 00d8d28 + be717ce commit 27ddc0c

File tree

4 files changed

+87
-80
lines changed

4 files changed

+87
-80
lines changed

R/sv_dependence2D.R

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ sv_dependence2D.shapviz <- function(
7474
add_vars = NULL,
7575
seed = 1L,
7676
...) {
77-
nplots <- max(length(x), length(y))
78-
79-
if (nplots == 1L) {
77+
if (max(length(x), length(y)) == 1L) {
8078
p <- .one_dependence2D_plot(
8179
object = object,
8280
x = x,
@@ -86,16 +84,18 @@ sv_dependence2D.shapviz <- function(
8684
jitter_height = jitter_height,
8785
interactions = interactions,
8886
add_vars = add_vars,
87+
title = NULL,
8988
seed = seed,
9089
...
9190
)
9291
return(p)
9392
}
93+
# mapply requires varying arguments with length > 0 -> NULL packed into list
9494
if (is.null(jitter_width)) {
95-
jitter_width <- replicate(nplots, NULL)
95+
jitter_width <- list(NULL)
9696
}
9797
if (is.null(jitter_height)) {
98-
jitter_height <- replicate(nplots, NULL)
98+
jitter_height <- list(NULL)
9999
}
100100
plot_list <- mapply(
101101
FUN = .one_dependence2D_plot,
@@ -109,6 +109,7 @@ sv_dependence2D.shapviz <- function(
109109
interactions = interactions,
110110
add_vars = add_vars,
111111
seed = seed,
112+
title = NULL, # not needed
112113
...
113114
),
114115
SIMPLIFY = FALSE
@@ -142,21 +143,26 @@ sv_dependence2D.mshapviz <- function(
142143
length(x) == 1L,
143144
length(y) == 1L
144145
)
145-
plot_list <- lapply(
146-
object,
146+
# mapply() does not allow varying arguments of length 0, thus we enclose NULL
147+
titles <- if (!is.null(names(object))) names(object) else list(NULL)
148+
149+
plot_list <- mapply(
147150
FUN = .one_dependence2D_plot,
148-
# Argument list (simplify via match.call() or some rlang magic?)
149-
x = x,
150-
y = y,
151-
viridis_args = viridis_args,
152-
jitter_width = jitter_width,
153-
jitter_height = jitter_height,
154-
interactions = interactions,
155-
add_vars = add_vars,
156-
seed = seed,
157-
...
151+
object,
152+
title = titles,
153+
MoreArgs = list(
154+
x = x,
155+
y = y,
156+
viridis_args = viridis_args,
157+
jitter_width = jitter_width,
158+
jitter_height = jitter_height,
159+
interactions = interactions,
160+
add_vars = add_vars,
161+
seed = seed,
162+
...
163+
),
164+
SIMPLIFY = FALSE
158165
)
159-
plot_list <- add_titles(plot_list, nms = names(object)) # see sv_waterfall()
160166

161167
# Collect axis titles, axes and guides
162168
coll <- .collect(plot_list)
@@ -178,6 +184,7 @@ sv_dependence2D.mshapviz <- function(
178184
jitter_height,
179185
interactions,
180186
add_vars,
187+
title,
181188
seed,
182189
...) {
183190
S <- get_shap_values(object)
@@ -227,6 +234,8 @@ sv_dependence2D.mshapviz <- function(
227234
legend.box.spacing = grid::unit(0, "pt"),
228235
legend.key.width = grid::unit(12, "pt")
229236
)
230-
237+
if (!is.null(title)) {
238+
p <- p + ggplot2::ggtitle(title)
239+
}
231240
return(p)
232241
}

cran-comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Slight adaptions to comply with upcoming XGBoost version.
1010

1111
Status: OK
1212

13-
## Reverse dependencies (2)
13+
## Reverse dependencies (3)
1414

15-
OK: 2
15+
OK: 3
1616
BROKEN: 0

revdep/README.md

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
11
# Platform
22

3-
|field |value |
4-
|:--------|:-------------------------------------|
5-
|version |R version 4.4.1 (2024-06-14 ucrt) |
6-
|os |Windows 11 x64 (build 22631) |
7-
|system |x86_64, mingw32 |
8-
|ui |RStudio |
9-
|language |(EN) |
10-
|collate |English_Switzerland.utf8 |
11-
|ctype |English_Switzerland.utf8 |
12-
|tz |Europe/Zurich |
13-
|date |2025-01-19 |
14-
|rstudio |2024.12.0+467 Kousa Dogwood (desktop) |
15-
|pandoc |NA |
3+
|field |value |
4+
|:--------|:---------------------------------------|
5+
|version |R version 4.4.1 (2024-06-14 ucrt) |
6+
|os |Windows 11 x64 (build 22631) |
7+
|system |x86_64, mingw32 |
8+
|ui |RStudio |
9+
|language |(EN) |
10+
|collate |English_Switzerland.utf8 |
11+
|ctype |English_Switzerland.utf8 |
12+
|tz |Europe/Zurich |
13+
|date |2025-06-22 |
14+
|rstudio |2025.05.0+496 Mariposa Orchid (desktop) |
15+
|pandoc |NA |
1616

1717
# Dependencies
1818

19-
|package |old |new |Δ |
20-
|:------------|:-------|:-------|:--|
21-
|shapviz |0.9.6 |0.9.7 |* |
22-
|cli |3.6.3 |3.6.3 | |
23-
|colorspace |2.1-1 |2.1-1 | |
24-
|commonmark |1.9.2 |1.9.2 | |
25-
|curl |6.1.0 |6.1.0 | |
26-
|data.table |1.16.4 |1.16.4 | |
27-
|fansi |1.0.6 |1.0.6 | |
28-
|farver |2.1.2 |2.1.2 | |
29-
|ggfittext |0.10.2 |0.10.2 | |
30-
|gggenes |0.5.1 |0.5.1 | |
31-
|ggplot2 |3.5.1 |3.5.1 | |
32-
|ggrepel |0.9.6 |0.9.6 | |
33-
|glue |1.8.0 |1.8.0 | |
34-
|gridtext |0.1.5 |0.1.5 | |
35-
|gtable |0.3.6 |0.3.6 | |
36-
|isoband |0.2.7 |0.2.7 | |
37-
|jpeg |0.1-10 |0.1-10 | |
38-
|jsonlite |1.8.9 |1.8.9 | |
39-
|labeling |0.4.3 |0.4.3 | |
40-
|lifecycle |1.0.4 |1.0.4 | |
41-
|magrittr |2.0.3 |2.0.3 | |
42-
|markdown |1.13 |1.13 | |
43-
|munsell |0.5.1 |0.5.1 | |
44-
|patchwork |1.3.0 |1.3.0 | |
45-
|pillar |1.10.1 |1.10.1 | |
46-
|pkgconfig |2.0.3 |2.0.3 | |
47-
|png |0.1-8 |0.1-8 | |
48-
|R6 |2.5.1 |2.5.1 | |
49-
|RColorBrewer |1.1-3 |1.1-3 | |
50-
|Rcpp |1.0.14 |1.0.14 | |
51-
|rlang |1.1.4 |1.1.4 | |
52-
|scales |1.3.0 |1.3.0 | |
53-
|shades |1.4.0 |1.4.0 | |
54-
|stringi |1.8.4 |1.8.4 | |
55-
|stringr |1.5.1 |1.5.1 | |
56-
|tibble |3.2.1 |3.2.1 | |
57-
|utf8 |1.2.4 |1.2.4 | |
58-
|vctrs |0.6.5 |0.6.5 | |
59-
|viridisLite |0.4.2 |0.4.2 | |
60-
|withr |3.0.2 |3.0.2 | |
61-
|xfun |0.50 |0.50 | |
62-
|xgboost |1.7.8.1 |1.7.8.1 | |
63-
|xml2 |1.3.6 |1.3.6 | |
19+
|package |old |new |Δ |
20+
|:------------|:--------|:--------|:--|
21+
|shapviz |0.9.7 |0.10.0 |* |
22+
|cli |3.6.5 |3.6.5 | |
23+
|commonmark |1.9.5 |1.9.5 | |
24+
|curl |6.3.0 |6.3.0 | |
25+
|data.table |1.17.6 |1.17.6 | |
26+
|farver |2.1.2 |2.1.2 | |
27+
|ggfittext |0.10.2 |0.10.2 | |
28+
|gggenes |0.5.1 |0.5.1 | |
29+
|ggplot2 |3.5.2 |3.5.2 | |
30+
|ggrepel |0.9.6 |0.9.6 | |
31+
|glue |1.8.0 |1.8.0 | |
32+
|gridtext |0.1.5 |0.1.5 | |
33+
|gtable |0.3.6 |0.3.6 | |
34+
|isoband |0.2.7 |0.2.7 | |
35+
|jpeg |0.1-11 |0.1-11 | |
36+
|jsonlite |2.0.0 |2.0.0 | |
37+
|labeling |0.4.3 |0.4.3 | |
38+
|lifecycle |1.0.4 |1.0.4 | |
39+
|litedown |0.7 |0.7 | |
40+
|magrittr |2.0.3 |2.0.3 | |
41+
|markdown |2.0 |2.0 | |
42+
|patchwork |1.3.1 |1.3.1 | |
43+
|pillar |1.10.2 |1.10.2 | |
44+
|pkgconfig |2.0.3 |2.0.3 | |
45+
|png |0.1-8 |0.1-8 | |
46+
|R6 |2.6.1 |2.6.1 | |
47+
|RColorBrewer |1.1-3 |1.1-3 | |
48+
|Rcpp |1.0.14 |1.0.14 | |
49+
|rlang |1.1.6 |1.1.6 | |
50+
|scales |1.4.0 |1.4.0 | |
51+
|shades |1.4.0 |1.4.0 | |
52+
|stringi |1.8.7 |1.8.7 | |
53+
|stringr |1.5.1 |1.5.1 | |
54+
|tibble |3.3.0 |3.3.0 | |
55+
|utf8 |1.2.6 |1.2.6 | |
56+
|vctrs |0.6.5 |0.6.5 | |
57+
|viridisLite |0.4.2 |0.4.2 | |
58+
|withr |3.0.2 |3.0.2 | |
59+
|xfun |0.52 |0.52 | |
60+
|xgboost |1.7.11.1 |1.7.11.1 | |
61+
|xml2 |1.3.8 |1.3.8 | |
6462

6563
# Revdeps
6664

revdep/cran.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## revdepcheck results
22

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

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

0 commit comments

Comments
 (0)