Skip to content

Commit

Permalink
[R] Run all plotting examples (#11101)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cortes authored Dec 15, 2024
1 parent 9191727 commit 874a690
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/r_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Install system dependencies
run: |
sudo apt update
sudo apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev
sudo apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev librsvg2-dev librsvg2-2
if: matrix.os == 'ubuntu-latest'
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
# Must run before checkout to have the latest git installed.
# No need to add pandoc, the container has it figured out.
apt update && apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev git -y
apt update && apt install libcurl4-openssl-dev libssl-dev libssh2-1-dev libgit2-dev libglpk-dev libxml2-dev libharfbuzz-dev libfribidi-dev git librsvg2-dev librsvg2-2 -y
- name: Trust git cloning project sources
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
Expand Down
3 changes: 3 additions & 0 deletions R-package/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Suggests:
rmarkdown,
ggplot2 (>= 1.0.1),
DiagrammeR (>= 0.9.0),
DiagrammeRsvg,
rsvg,
htmlwidgets,
Ckmeans.1d.dp (>= 3.3.1),
vcd (>= 1.3),
testthat,
Expand Down
13 changes: 4 additions & 9 deletions R-package/R/xgb.plot.multi.trees.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@
#' p <- xgb.plot.multi.trees(model = bst, features_keep = 3)
#' print(p)
#'
#' \dontrun{
#' # Below is an example of how to save this plot to a file.
#' # Note that for export_graph() to work, the {DiagrammeRsvg} and {rsvg} packages
#' # must also be installed.
#'
#' library(DiagrammeR)
#'
#' gr <- xgb.plot.multi.trees(model = bst, features_keep = 3, render = FALSE)
#' export_graph(gr, "tree.pdf", width = 1500, height = 600)
#' if (require("DiagrammeR") && require("DiagrammeRsvg") && require("rsvg")) {
#' fname <- file.path(tempdir(), "tree.pdf")
#' gr <- xgb.plot.multi.trees(bst, features_keep = 3, render = FALSE)
#' export_graph(gr, fname, width = 1500, height = 600)
#' }
#'
#' @export
xgb.plot.multi.trees <- function(model, features_keep = 5, plot_width = NULL, plot_height = NULL,
render = TRUE, ...) {
Expand Down
12 changes: 4 additions & 8 deletions R-package/R/xgb.plot.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@
#' # plot the first tree
#' xgb.plot.tree(model = bst, tree_idx = 1)
#'
#'
#' \dontrun{
#' # Below is an example of how to save this plot to a file.
#'
#' library(DiagrammeR)
#'
#' gr <- xgb.plot.tree(model = bst, tree_idx = 1)
#' htmlwidgets::saveWidget(gr, 'plot.html')
#' if (require("DiagrammeR") && require("htmlwidgets")) {
#' fname <- file.path(tempdir(), "plot.html'")
#' gr <- xgb.plot.tree(bst, tree_idx = 1)
#' htmlwidgets::saveWidget(gr, fname)
#' }
#'
#' @export
xgb.plot.tree <- function(model,
tree_idx = 1,
Expand Down
13 changes: 4 additions & 9 deletions R-package/man/xgb.plot.multi.trees.Rd

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

12 changes: 4 additions & 8 deletions R-package/man/xgb.plot.tree.Rd

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

3 changes: 3 additions & 0 deletions R-package/tests/helper_scripts/install_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pkgs <- c(
"rmarkdown",
"ggplot2",
"DiagrammeR",
"DiagrammeRsvg",
"rsvg",
"htmlwidgets",
"Ckmeans.1d.dp",
"vcd",
"lintr",
Expand Down

0 comments on commit 874a690

Please sign in to comment.