[Rd] plotmath indices: suggested addition to help file

Martin Maechler maechler at stat.math.ethz.ch
Fri Jan 21 15:32:14 CET 2011

>>>>> "PE" == Peter Ehlers <ehlers at ucalgary.ca>
>>>>>     on Fri, 21 Jan 2011 06:17:20 -0800 writes:

    PE> On 2011-01-21 02:27, Martin Maechler wrote:
    >> Thank you, Claudia,
    >>>>>>> "CB" == Claudia Beleites<cbeleites at units.it> on Thu,
    >>>>>>> 20 Jan 2011 14:05:41 +0100 writes:
    CB> Dear all, I just stumbled over the fact that subsetting
    CB> by square bracket will only output the first given
    CB> index. I guess the rest is thrown away by the CADDR in
    CB> RenderSub (plotmath.c l. 1399).  Maybe changing this
    CB> could be considered as "low-priority desired" (would be
    CB> nice if the output works for ?
    >> I agree this is a ``missing feature'' and well worth wish
    >> list item.
    CB> However, I suggest to announce the fact that only the
    CB> first parameter is printed in plotmath.Rd.
    CB> E.g. in the table l. 72 \code{x[i]} \tab x subscript i;
    CB> escape further indices (\code{x ["i, j"]})\cr
    >> How would get the equivalent of LaTeX x_{i_1, j_2} ?  Not
    >> by making it a string (that's not escape, I'd say), but
    >> by something like
    >> plot(0, axes=FALSE, main=
    >> expression(paste(x[i[1]],{}[j[2]])))
    >> which works +- but of course is unnecessarily ugly,
    >> compared to the desired
    >> plot(0, axes=FALSE, main= expression( x[i[1], j[2]]))

    PE> I don't know if I've ever disagreed with Martin's advice but,

    PE> unless I'm missing something, Claudia wants something
    PE> done about the second index in x[i, j] while Martin is
    PE> talking about the case of cascading subscripts in
    PE> 'x_sub_i_sub_1' (as shown in his LaTeX expression).

Well, that was a misunderstanding.
I've use "cascaded" subscripts as an example of subscripts that
are themselves expressions, and so using a string,
as Claudia's suggestion (on R-devel!) was, is not enough.

Only afterwards, I saw the related thread on R-help,
which included the proposals you give here

    PE> Both situations are nicely handled with the 'list()' and '[]'
    PE> constructs in plotmath:

    PE> plot(0, axes=FALSE, main= expression( x[ list( i[1], j[2] ) ] ) )

    PE> To handle Claudia's wish, it might be desirable to have plotmath.c
    PE> automatically recognize such cases but I would consider that to
    PE> be (as Claudia says) in the 'nice if' category. Claudia's suggestion
    PE> for the help page could be handled by adding another example. Then
    PE> again, plotmath (not surprisingly) is like LaTeX in that, the more
    PE> you use it, the more you become familiar with the special constructs
    PE> needed to get the output you want. I still find myself scurrying to
    PE> ?plotmath and scanning the Syntax/Meaning table quite frequently.

Indeed, the following code snippet shows what I deem a summary
of the proposals seen.

Txt <- function(y, exp) {
    y <- y/16 # to allow integer arguments on input
    x0 <- par("xaxp")[1]
    text(y, exp, adj = 0, cex = 5)
    text(y, deparse(substitute(exp)), adj = 1.1, cex=1.2)
plot(0, axes=FALSE,ann=FALSE, asp=1, type="n")
## These show no "," between the two indices:
Txt( 0, expression(x[paste(i[1],j[2])]))
Txt( 2, expression(x[i[1]][j[2]])) ## <-- clearly nicest
## This one does .. that's what Claudia wanted:
Txt(-3, expression(x[list(i[1],j[2])]))
## and this one uses extra space
Txt(-5, expression(x[list(~i[1],j[2])]))
g <- seq(-1.6,1, .2)/4; abline(v=g+1, h=g, col=adjustcolor(1, .2))

Notably the distinction between (LaTeX)   
   x_{i,j}  or  x_{i_1, j_2}
   x_{ij}   or   x_{i_1 i_2}

is something that the useR will want to be able to specify with
plotmath as well.
So Claudia's (and my) wish that   x[i,j]  (or x[i[1], j[2]] )
also work automatically in R's plotmath
would still have to say if we want the version with "," or


    PE> Peter Ehlers

    >> Martin
    CB> Claudia

More information about the R-devel mailing list