Skip to content

Commit f0c80a7

Browse files
committed
Turn fix_labeller() into a check function
1 parent 9260dbc commit f0c80a7

File tree

5 files changed

+13
-28
lines changed

5 files changed

+13
-28
lines changed

R/facet-grid-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
176176
facets_list <- grid_as_facets_list(rows, cols)
177177

178178
# Check for deprecated labellers
179-
labeller <- fix_labeller(labeller)
179+
check_labeller(labeller)
180180

181181
ggproto(NULL, FacetGrid,
182182
shrink = shrink,

R/facet-wrap.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
174174
)
175175

176176
# Check for deprecated labellers
177-
labeller <- fix_labeller(labeller)
177+
check_labeller(labeller)
178178

179179
# Flatten all facets dimensions into a single one
180180
facets <- compact_facets(facets)

R/labeller.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,22 +577,18 @@ assemble_strips <- function(grobs, theme, horizontal = TRUE, clip) {
577577
})
578578
}
579579

580-
# Repair old school labeller
581-
fix_labeller <- function(labeller) {
580+
# Reject old school labeller
581+
check_labeller <- function(labeller) {
582+
582583
labeller <- match.fun(labeller)
583584
is_deprecated <- all(c("variable", "value") %in% names(formals(labeller)))
584585

585-
if (is_deprecated) {
586-
deprecate_warn0(
587-
"2.0.0", what = "facet_(labeller)",
588-
details =
589-
"Modern labellers do not take `variable` and `value` arguments anymore."
590-
)
591-
old_labeller <- labeller
592-
labeller <- function(labels) {
593-
Map(old_labeller, names(labels), labels)
594-
}
586+
if (!is_deprecated) {
587+
return(invisible())
595588
}
596589

597-
labeller
590+
lifecycle::deprecate_stop(
591+
"2.0.0",
592+
what = I("Providing a labeller with `variable` and `value` arguments")
593+
)
598594
}

tests/testthat/_snaps/facet-labels.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,3 @@
1414
Error in `labeller()`:
1515
! Conflict between `.cols` and `cyl`.
1616

17-
# old school labellers still work
18-
19-
The `labeller` argument of `facet_()` is deprecated as of ggplot2 2.0.0.
20-
i Modern labellers do not take `variable` and `value` arguments anymore.
21-

tests/testthat/test-facet-labels.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,12 @@ test_that("as_labeller() deals with non-labellers", {
130130
expect_equal(get_labels_matrix(p2), cbind(c("0-foo", "1-foo")))
131131
})
132132

133-
test_that("old school labellers still work", {
133+
test_that("old school labellers are deprecated", {
134134
my_labeller <- function(variable, value) {
135135
paste0("var = ", as.character(value))
136136
}
137137

138-
expect_snapshot_warning(p <-
139-
ggplot(mtcars, aes(disp, drat)) +
140-
geom_point() +
141-
facet_grid(~cyl, labeller = my_labeller))
142-
143-
expected_labels <- cbind(paste("var =", c(4, 6, 8)))
144-
expect_identical(get_labels_matrix(p, "cols"), expected_labels)
138+
lifecycle::expect_defunct(facet_grid(~cyl, labeller = my_labeller))
145139
})
146140

147141

0 commit comments

Comments
 (0)