Skip to content

Fix reverse dependency issue with facet labelling #6471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/facet-grid-.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
facets_list <- grid_as_facets_list(rows, cols)

# Check for deprecated labellers
check_labeller(labeller)
labeller <- validate_labeller(labeller)

ggproto(NULL, FacetGrid,
shrink = shrink,
Expand Down
2 changes: 1 addition & 1 deletion R/facet-wrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
)

# Check for deprecated labellers
check_labeller(labeller)
labeller <- validate_labeller(labeller)

# Flatten all facets dimensions into a single one
facets <- compact_facets(facets)
Expand Down
4 changes: 2 additions & 2 deletions R/labeller.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,13 @@ assemble_strips <- function(grobs, theme, horizontal = TRUE, clip) {
}

# Reject old school labeller
check_labeller <- function(labeller) {
validate_labeller <- function(labeller) {

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

if (!is_deprecated) {
return(invisible())
return(labeller)
}

lifecycle::deprecate_stop(
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-labellers.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
test_that("facets convert labeller to function", {
f <- facet_grid(foo ~ bar, labeller = "label_both")
expect_type(f$params$labeller, "closure")

f <- facet_wrap(foo ~ bar, labeller = "label_value")
expect_type(f$params$labeller, "closure")
})

test_that("label_bquote has access to functions in the calling environment", {
labels <- data.frame(lab = letters[1:2])
attr(labels, "facet") <- "wrap"
Expand Down