[R] percentage sign in expression

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Aug 26 09:49:26 CEST 2010


On Thu, 2010-08-26 at 08:17 +0100, e-letter wrote:
> >On Wed, 2010-08-25 at 09:32 +0100, e-letter wrote:
> >> On 24/08/2010, David Winsemius <dwinsemius at comcast.net> wrote:
> >> >
> >> > On Aug 24, 2010, at 9:37 AM, e-letter wrote:
> >> >
> >> >> Readers,
> >> >>
> >> >> According to the documentation for the function 'plotmath' there is no
> >> >> apparent possibility to add the percent sign (%) to a plot function,
> >> >
> >> > Where did you see an assertion made???
> >> >
> >> Within R I entered the command:
> >>
> >> ?plotmath
> >
> >Surely you don't expect the R help pages to document everything that
> >*isn't* possible with a given function? They'd be infinitely long! ;-)
> >
> No, following previous advice it would be preferable to add the
> following (or similar) to the documentation:
> 
> 'syntax' 'meaning'
> ...
> '%' %
> ...

Should we also get the R devs to add

'a' a
'b' b
....

?

This is just literal text. And as such is not what plotmath is all
about, which is providing notation for common mathematical symbology.
'%' is not, it is plain text. And that is handled by expression() or
bquote() etc. Nothing to do with plotmath.

Note that it does go into details of how to view the glyphs available
with the symbol font on your machine (using the TestChars() function
available in the example section of ?points ) and then plot these glyphs
in both the main body of the help page and in the example. So it is
documented there, but again, do you want the devs to do:

'syntax'       'Meaning'
symbol("\042")    FOO
symbol("\043")    BAR
....

How do they handle different availability of glyphs on the various OSes
that there might be etc? Hence the TestChars() and generic instructions
on how to draw all glyphs in your systems symbol font. It just requires
a little bit more effort on your part to find the correct \xxx code.

G

> >What you meant to say was, "?plotmath doesn't show me how to add a %
> >symbol to a plot. How do I do it?"
> >
> >> Also accessed using:
> >>
> >> help.start(browser="opera")
> >>
> >> Navigating the web browser page:
> >>
> >> packages
> >> packages in /usr/lib/R/library
> >> grdevices
> >> plotmath
> >>
> >> In the list headed 'syntax' and 'meaning' within the section 'details'.
> >>
> ><snip />
> >> >  > TestChars <- function(sign=1, font=1, ...)
> >> > + {
> >> > +    if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
> >> > +    } else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
> >> > +    if (sign == -1) r <- c(32:126, 160:255)
> >> > +    par(pty="s")
> >> > +    plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
> >> > +         xaxs="i", yaxs="i")
> >> > +    grid(17, 17, lty=1)
> >> > +    for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
> >> > + }
> >> >  > TestChars(font=5)
> >> >
> >> > Notice that the "%" sign is three characters to the right (i.e.
> >> > higher) of the "forall" symbol that is produced by the example code
> >>
> >> I can't see 'forall' in the code above.
> >
> >You need to run it in R. Then you will see a plot of the glyphs
> >available in the symbol font. 'forall' is a mathematical symbol:
> >
> >http://en.wikipedia.org/wiki/Table_of_mathematical_symbols
> >
> >> > they offer. (The numbering proceeds from bottom up which confused me
> >> > at first.)
> >> >
> >> What numbering?
> >
> >The numbering of the glyphs so you can use the number to draw the symbol
> >you want. They are on the plot. You did run the code provided by David?
> >
> I did not read any instruction that it was code to apply! Anyway,
> below is the result:
> 
> > TestChars <- function(sign=1, font=1, ...)
> + + {
> + +    if(font == 5) { sign <- 1; r <- c(32:126, 160:254)
> + +    } else if (l10n_info()$MBCS) r <- 32:126 else r <- 32:255
> Error: syntax error, unexpected '}' in:
> "
> "
> > +    if (sign == -1) r <- c(32:126, 160:255)
> Error in sign == -1 : comparison (1) is possible only for atomic and list types
> > +    par(pty="s")
> Error in +par(pty = "s") : invalid argument to unary operator
> > +    plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="",
> + +         xaxs="i", yaxs="i")
> Error: syntax error, unexpected EQ_ASSIGN, expecting ',' in "+
> plot(c(-1,16), c(-1,16), type="n", xlab="", ylab="","
> > +    grid(17, 17, lty=1)
> Error in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
>         plot.new has not been called yet
> > +    for(i in r) try(points(i%%16, i%/%16, pch=sign*i, font=font,...))
> Error: object "r" not found
> > + }
> Error: syntax error, unexpected '}' in "+ }"
> > TestChars(font=5)
> Error: could not find function "TestChars"
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list