diff --git a/NEWS.md b/NEWS.md
index 489dbe6c..811ba218 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -276,6 +276,10 @@ Theme fixes:
- `plt(..., ann = FALSE)` correctly turns off title annotations now, fixing a
regression that we missed from at least v0.6.0. Thanks to @bastistician for
the report. (#641 @zeileis)
+- Fixed `bquote()` (and other unevaluated language) annotations such as `main`,
+ `sub`, `cap`, `xlab`, and `ylab` being evaluated instead of coerced to
+ plotmath expressions, e.g. `plt(0, 0, main = bquote(foo == .(pi)))`. Thanks
+ (again) to @bastistician for the report. (#642 @grantmcdermott)
## v0.6.1
diff --git a/R/title.R b/R/title.R
index bf0dfb2a..672ee2d9 100644
--- a/R/title.R
+++ b/R/title.R
@@ -68,7 +68,7 @@ draw_title = function(main, sub, cap, xlab, ylab, legend, legend_args, opar,
las = 1
)
args = Filter(function(x) !is.null(x), args)
- do.call(mtext, args)
+ do.call(mtext, args, quote = TRUE)
}
if (!is.null(main)) {
@@ -88,7 +88,7 @@ draw_title = function(main, sub, cap, xlab, ylab, legend, legend_args, opar,
font.main = get_tpar("font.main", 2),
adj = get_tpar(c("adj.main", "adj"), 3))
args = Filter(function(x) !is.null(x), args)
- do.call(title, args)
+ do.call(title, args, quote = TRUE)
par(xpd = .oxpd)
}
@@ -111,7 +111,7 @@ draw_title = function(main, sub, cap, xlab, ylab, legend, legend_args, opar,
las = 1
)
args = Filter(function(x) !is.null(x), args)
- do.call(mtext, args)
+ do.call(mtext, args, quote = TRUE)
}
# Axis titles. For multi-line labels, base R places line 1 at
@@ -138,7 +138,7 @@ draw_title = function(main, sub, cap, xlab, ylab, legend, legend_args, opar,
}
args[["adj"]] = get_tpar(c("adj.xlab", "adj"))
args[["cex.lab"]] = cex_xlab
- do.call(title, args)
+ do.call(title, args, quote = TRUE)
# ylab: base R already places multi-line text correctly (outermost line at
# mgp[1], subsequent lines closer to the plot), so no line shift needed.
@@ -149,5 +149,5 @@ draw_title = function(main, sub, cap, xlab, ylab, legend, legend_args, opar,
}
args[["adj"]] = get_tpar(c("adj.ylab", "adj"))
args[["cex.lab"]] = cex_ylab
- do.call(title, args)
+ do.call(title, args, quote = TRUE)
}
diff --git a/inst/tinytest/_tinysnapshot/titles-bquote-kitchen.svg b/inst/tinytest/_tinysnapshot/titles-bquote-kitchen.svg
new file mode 100644
index 00000000..927503b8
--- /dev/null
+++ b/inst/tinytest/_tinysnapshot/titles-bquote-kitchen.svg
@@ -0,0 +1,66 @@
+
+
diff --git a/inst/tinytest/_tinysnapshot/titles-bquote-pi.svg b/inst/tinytest/_tinysnapshot/titles-bquote-pi.svg
new file mode 100644
index 00000000..2a8b503f
--- /dev/null
+++ b/inst/tinytest/_tinysnapshot/titles-bquote-pi.svg
@@ -0,0 +1,59 @@
+
+
diff --git a/inst/tinytest/test-misc.R b/inst/tinytest/test-misc.R
index 586bc6bf..e55fed32 100644
--- a/inst/tinytest/test-misc.R
+++ b/inst/tinytest/test-misc.R
@@ -153,4 +153,28 @@ expect_snapshot_plot(f, label = "formula_y1_cust_lab")
f = function() {
plt(0, 0, ann = FALSE)
}
-expect_snapshot_plot(f, label = "ann=FALSE")
\ No newline at end of file
+expect_snapshot_plot(f, label = "ann=FALSE")
+
+
+# bquote() and other unevaluated/language annotations must be coerced
+# to plotmath expressions, not evaluated. (#624)
+
+f = function() {
+ plt(0, 0, type = "n", main = bquote(pi == .(pi)))
+}
+expect_snapshot_plot(f, label = "titles-bquote-pi")
+
+# kitchen sink: every annotation slot a (different) language object at once
+f = function() {
+ plt(
+ 0, 0,
+ type = "n",
+ main = bquote(pi == .(round(pi, 2))),
+ sub = bquote(n == .(42L)),
+ xlab = bquote(x[i]^2),
+ ylab = bquote(sqrt(y)),
+ cap = bquote(italic("source: foo")),
+ theme = "dynamic"
+ )
+}
+expect_snapshot_plot(f, label = "titles-bquote-kitchen")