Skip to content

Commit

Permalink
Reverting #697 (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Puzzled-Face authored Nov 1, 2023
1 parent a25d682 commit 3bfa245
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,gtable)
S3method(print,gtable)
export("%>%")
export(.CohortSizeConst)
export(.CohortSizeDLT)
Expand Down Expand Up @@ -565,6 +567,7 @@ importFrom(graphics,lines)
importFrom(graphics,matlines)
importFrom(graphics,matplot)
importFrom(graphics,plot)
importFrom(grid,grid.draw)
importFrom(gridExtra,arrangeGrob)
importFrom(kableExtra,add_footnote)
importFrom(kableExtra,add_header_above)
Expand Down
1 change: 1 addition & 0 deletions R/crmPack-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#' @import ggplot2
#' @import methods
#' @import tibble
#' @importFrom grid grid.draw
#' @importFrom gridExtra arrangeGrob
#' @importFrom graphics plot hist legend lines matlines matplot
#' @importFrom stats binomial coef cov2cor gaussian glm lm median model.matrix
Expand Down
22 changes: 22 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ crmPackHelp <- function() {
utils::help(package = "crmPack", help_type = "html")
}

#' Plot `gtable` Objects
#'
#' This is needed because `crmPack` uses [gridExtra::arrangeGrob()] to combine
#' `ggplot2` plots, and the resulting `gtable` object is not plotted otherwise
#' when implicitly printing it in the console, e.g.
#'
#' @method plot gtable
#' @param x (`gtable`)\cr object to plot.
#' @param ... additional parameters for [grid::grid.draw()].
#'
#' @export
plot.gtable <- function(x, ...) {
grid::grid.draw(x, ...)
}

#' @method print gtable
#' @rdname plot.gtable
#' @export
print.gtable <- function(x, ...) {
plot(x, ...)
}

##' Taken from utils package (print.vignette)
##'
##' @importFrom tools file_ext
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ reference:
- plot,SimulationsSummary,missing-method
- plotDualResponses
- plotGain
- plot.gtable
- probit
- set_seed
- show,DualSimulationsSummary-method
Expand Down
21 changes: 21 additions & 0 deletions man/plot.gtable.Rd

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

4 changes: 2 additions & 2 deletions man/simulate-DesignGrouped-method.Rd

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

24 changes: 24 additions & 0 deletions tests/testthat/_snaps/helpers/plot-gtable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/helpers/print-gtable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/testthat/test-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,19 @@ test_that("h_group_data works as expected", {
)
expect_setequal(combo_data_from_group, combo_data_from_start)
})

# print.gtable ----

test_that("print for gtable works", {
result <- gridExtra::arrangeGrob(grid::rectGrob(), grid::rectGrob())
assert_class(result, "gtable")
vdiffr::expect_doppelganger("print-gtable", result)
})

# plot.gtable ----

test_that("plot for gtable works", {
result <- gridExtra::arrangeGrob(grid::rectGrob(), grid::rectGrob())
assert_class(result, "gtable")
vdiffr::expect_doppelganger("plot-gtable", plot(result))
})

0 comments on commit 3bfa245

Please sign in to comment.