Skip to content

Commit 68ab7bf

Browse files
authored
Fix reverse dependency issue with facet labelling (#6471)
* convert `check_labeller()` to `validate_labeller()` * add small test
1 parent b1c27f1 commit 68ab7bf

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

R/facet-grid-.R

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

189189
# Check for deprecated labellers
190-
check_labeller(labeller)
190+
labeller <- validate_labeller(labeller)
191191

192192
ggproto(NULL, FacetGrid,
193193
shrink = shrink,

R/facet-wrap.R

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

190190
# Check for deprecated labellers
191-
check_labeller(labeller)
191+
labeller <- validate_labeller(labeller)
192192

193193
# Flatten all facets dimensions into a single one
194194
facets <- compact_facets(facets)

R/labeller.R

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

580580
# Reject old school labeller
581-
check_labeller <- function(labeller) {
581+
validate_labeller <- function(labeller) {
582582

583583
labeller <- match.fun(labeller)
584584
is_deprecated <- all(c("variable", "value") %in% names(formals(labeller)))
585585

586586
if (!is_deprecated) {
587-
return(invisible())
587+
return(labeller)
588588
}
589589

590590
lifecycle::deprecate_stop(

tests/testthat/test-labellers.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
test_that("facets convert labeller to function", {
2+
f <- facet_grid(foo ~ bar, labeller = "label_both")
3+
expect_type(f$params$labeller, "closure")
4+
5+
f <- facet_wrap(foo ~ bar, labeller = "label_value")
6+
expect_type(f$params$labeller, "closure")
7+
})
8+
19
test_that("label_bquote has access to functions in the calling environment", {
210
labels <- data.frame(lab = letters[1:2])
311
attr(labels, "facet") <- "wrap"

0 commit comments

Comments
 (0)