Skip to content

Commit ce15ec1

Browse files
committed
more concise as_labeller
1 parent 5331072 commit ce15ec1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

R/labeller.r

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ resolve_labeller <- function(rows, cols, labels) {
297297
#' # your labeller to the right variable with labeller()
298298
#' p + facet_grid(cyl ~ am, labeller = labeller(am = to_string))
299299
as_labeller <- function(x, default = label_value, multi_line = TRUE) {
300-
if(is.formula(x)) x <- as_function(x)
301300
force(x)
302301
fun <- function(labels) {
303302
labels <- lapply(labels, as.character)
@@ -312,6 +311,8 @@ as_labeller <- function(x, default = label_value, multi_line = TRUE) {
312311
x(labels)
313312
} else if (is.function(x)) {
314313
default(lapply(labels, x))
314+
} else if (is.formula(x)) {
315+
default(lapply(labels, as_function(x)))
315316
} else if (is.character(x)) {
316317
default(lapply(labels, function(label) x[label]))
317318
} else {
@@ -430,11 +431,6 @@ labeller <- function(..., .rows = NULL, .cols = NULL,
430431

431432
dots <- list(...)
432433

433-
if (length(dots) == 1) {
434-
if (is.formula(dots[[1]]) || is.function(dots[[1]]) && !is_labeller(dots[[1]])) {
435-
return(as_labeller(dots[[1]]))
436-
}
437-
}
438434

439435
.default <- as_labeller(.default)
440436

@@ -562,7 +558,11 @@ build_strip <- function(label_df, labeller, theme, horizontal) {
562558
#'
563559
#' @noRd
564560
assemble_strips <- function(grobs, theme, horizontal = TRUE, clip) {
565-
if (length(grobs) == 0 || is.zero(grobs[[1]])) return(grobs)
561+
if (length(grobs) == 0 || is.zero(grobs[[1]])) {
562+
# Subsets matrix of zeroGrobs to correct length (#4050)
563+
grobs <- grobs[seq_len(NROW(grobs))]
564+
return(grobs)
565+
}
566566

567567
# Add margins to non-titleGrobs so they behave eqivalently
568568
grobs[] <- lapply(grobs, function(g) {

0 commit comments

Comments
 (0)