Skip to content

Commit

Permalink
Move {MASS} to Suggests (#5993)
Browse files Browse the repository at this point in the history
* add `check_installed("MASS")` where appropriate

* pre-populate parameters

* move MASS

* conditionally skip that that require MASS

* fence in example

* Revert "fence in example"

This reverts commit 93295f5.

* fence-in correct piece this time

* sneak in forgotten news bullet
  • Loading branch information
teunbrand authored Nov 11, 2024
1 parent 926f290 commit 7b62271
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Imports:
gtable (>= 0.1.1),
isoband,
lifecycle (> 1.0.1),
MASS,
rlang (>= 1.1.0),
scales (>= 1.3.0),
stats,
Expand All @@ -53,6 +52,7 @@ Suggests:
knitr,
mapproj,
maps,
MASS,
mgcv,
multcomp,
munsell,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* `geom_errorbarh()` is deprecated in favour of
`geom_errorbar(orientation = "y")` (@teunbrand, #5961).
* `geom_contour()` should be able to recognise a rotated grid of points
(@teunbrand, #4320)
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
Expand Down
1 change: 1 addition & 0 deletions R/stat-density-2d.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
contour_type = "lines",

compute_layer = function(self, data, params, layout) {
check_installed("MASS", reason = "for calculating 2D density.")
# first run the regular layer calculation to infer densities
data <- ggproto_parent(Stat, self)$compute_layer(data, params, layout)

Expand Down
8 changes: 8 additions & 0 deletions R/stat-ellipse.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ stat_ellipse <- function(mapping = NULL, data = NULL,
StatEllipse <- ggproto("StatEllipse", Stat,
required_aes = c("x", "y"),

setup_params = function(data, params) {
params$type <- params$type %||% "t"
if (identical(params$type, "t")) {
check_installed("MASS", "for calculating ellipses with `type = \"t\"`.")
}
params
},

compute_group = function(data, scales, type = "t", level = 0.95,
segments = 51, na.rm = FALSE) {
calculate_ellipse(data = data, vars = c("x", "y"), type = type,
Expand Down
8 changes: 6 additions & 2 deletions R/stat-qq.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
#' p <- ggplot(df, aes(sample = y))
#' p + stat_qq() + stat_qq_line()
#'
#' # Use fitdistr from MASS to estimate distribution params
#' params <- as.list(MASS::fitdistr(df$y, "t")$estimate)
#' # Use fitdistr from MASS to estimate distribution params:
#' # if (requireNamespace("MASS", quietly = TRUE)) {
#' # params <- as.list(MASS::fitdistr(df$y, "t")$estimate)
#' # }
#' # Here, we use pre-computed params
#' params <- list(m = -0.02505057194115, s = 1.122568610124, df = 6.63842653897)
#' ggplot(df, aes(sample = y)) +
#' stat_qq(distribution = qt, dparams = params["df"]) +
#' stat_qq_line(distribution = qt, dparams = params["df"])
Expand Down
8 changes: 6 additions & 2 deletions man/geom_qq.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/test-stat-density2d.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("MASS")

test_that("uses scale limits, not data limits", {
base <- ggplot(mtcars, aes(wt, mpg)) +
stat_density_2d() +
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-stat-ellipsis.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("MASS")

test_that("stat_ellipsis returns correct data format", {
n_seg <- 40
d <- data_frame(x = c(1, 1, 4, 4, 4, 3, 3, 1), y = c(1:4, 1:4), id = rep(1:2, each = 4))
Expand Down

0 comments on commit 7b62271

Please sign in to comment.