Skip to content
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions R/title.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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)
}
66 changes: 66 additions & 0 deletions inst/tinytest/_tinysnapshot/titles-bquote-kitchen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions inst/tinytest/_tinysnapshot/titles-bquote-pi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion inst/tinytest/test-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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")