Skip to content

Commit 8188a86

Browse files
author
murrell
committed
fix for PR 7084; thanks to Heather Turner and Ella Kaye
git-svn-id: https://svn.r-project.org/R/trunk@88305 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 8e41488 commit 8188a86

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/NEWS.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
\item \code{t.test(c(1:3, Inf))} and similar no longer produce an error but
143143
return a (still not so useful) \code{"htest"} result, fixing
144144
\PR{18901}, thanks to \I{Jesse Alderliesten}.
145+
146+
\item \code{text()} now truncates \code{labels} to maximum length
147+
of \code{x} and \code{y} (if it is longer), fixing \PR{7084}.
148+
Thanks to \I{Heather Turner} and \I{Ella Kaye}.
145149
}
146150
}
147151
}

src/library/graphics/R/text.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ function(x, y = NULL, labels = seq_along(x$x),
2626
if (!missing(y) && (is.character(y) || is.expression(y))) {
2727
labels <- y; y <- NULL
2828
}
29+
2930
x <- xy.coords(x,y, recycle = TRUE, setLab = FALSE)
31+
32+
if (is.language(labels)) {
33+
labels <- as.expression(labels)
34+
}
35+
36+
if (length(labels) > (n <- length(x$x)) && n >= 1) {
37+
labels <- labels[1:n]
38+
warning("length(labels) > max(length(x), length(y)). labels truncated to length ", n, ".")
39+
}
40+
3041
labels <- as.graphicsAnnot(labels)
3142
if (!is.null(vfont))
3243
vfont <- c(typeface = pmatch(vfont[1L], Hershey$typeface),

src/library/graphics/man/text.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ text(x, \dots)
2424
language objects (names and calls) to expressions, and vectors and
2525
other classed objects to character vectors by \code{\link{as.character}}.
2626
If \code{labels} is longer than \code{x} and
27-
\code{y}, the coordinates are recycled to the length of \code{labels}.}
27+
\code{y}, \code{labels} is truncated to \code{max(length(x), length(y))}.}
2828
\item{adj}{one or two values in \eqn{[0, 1]} which specify the x
2929
(and optionally y) adjustment (\sQuote{justification}) of the
3030
labels, with 0 for left/bottom, 1 for right/top, and 0.5 for

0 commit comments

Comments
 (0)