From 763e38eaabe3c6ce6feef26f05210c45aa830a33 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Wed, 14 Apr 2021 09:59:26 +0200 Subject: [PATCH 1/2] Make sure that expressions are reencoded as expressions when collapsed --- NEWS.md | 3 +++ R/labeller.r | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 60159e47bf..73d04085a1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # ggplot2 (development version) +* Fix bug in `labeller()` where parsing was turned off if `.multiline = FALSE` + (@thomasp85, #4084) + * Fix bug in `geom_dotplot()` where dots would be positioned wrong with `stackgroups = TRUE` (@thomasp85, #1745) diff --git a/R/labeller.r b/R/labeller.r index 0d47f4eb0c..53839f5cfd 100644 --- a/R/labeller.r +++ b/R/labeller.r @@ -88,8 +88,13 @@ NULL collapse_labels_lines <- function(labels) { + is_exp <- vapply(labels, function(l) length(l) > 0 && is.expression(l[[1]]), logical(1)) out <- do.call("Map", c(list(paste, sep = ", "), labels)) - list(unname(unlist(out))) + label <- list(unname(unlist(out))) + if (any(is_exp)) { + label <- lapply(label, function(l) list(parse(text = paste0("list(", l, ")")))) + } + label } #' @rdname labellers From 26a13716ffdeab0df737aa071bcde5be3bf6d4b2 Mon Sep 17 00:00:00 2001 From: Thomas Lin Pedersen Date: Wed, 14 Apr 2021 10:47:38 +0200 Subject: [PATCH 2/2] only reparse if all labels are expressions --- R/labeller.r | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/labeller.r b/R/labeller.r index 53839f5cfd..099a2d961d 100644 --- a/R/labeller.r +++ b/R/labeller.r @@ -91,7 +91,7 @@ collapse_labels_lines <- function(labels) { is_exp <- vapply(labels, function(l) length(l) > 0 && is.expression(l[[1]]), logical(1)) out <- do.call("Map", c(list(paste, sep = ", "), labels)) label <- list(unname(unlist(out))) - if (any(is_exp)) { + if (all(is_exp)) { label <- lapply(label, function(l) list(parse(text = paste0("list(", l, ")")))) } label