[R] format backslash behaviour

Prof Brian D Ripley ripley at stats.ox.ac.uk
Mon May 10 09:02:58 CEST 1999


On Mon, 10 May 1999, John Peters wrote:

> 
> The following seems weird:
> 
> > format("\pm2")
> [1] "pm2"
> 
> > format("\\pm2")
> [1] "\\\\pm2"
> > 
> 
> i.e. it seems impossible to set up a x so that "format(x)" returns 
> "\\pm2", and in turn "cat(format(x))" prints "\pm2".  ("\pm" is latex for 
> "plus/minus").
> 
> R is version 0.64 for win95.

No such version, that I know of. I assume you have 0.64.0 for
Windows (rw0640)

> 
> I want to add a row of headings to a matrix of character objects, then 
> use "format" on each column to make the matrix less ragged (not 
> essential), and cat the result for use as a latex table.
> 
> Splus 3.4 does the same, and I currently regard compatibility with Splus 
> as a very convenient feature, so I suppose it is not a bug.
> 
> I would appreciate any explanations for the behaviour, and any hints 
> about neat workarounds.

If M is your matrix,

M[] <- gsub("\\\\\\\\", "\\\\", M)
write(M, ncol=ncol(M), file="whatever")

does the trick for me. (That turns "\\\\pm2" into "\\pm2" that write
then prints as "\pm2". Beware: print prints it as "\\pm2".)

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list