[R] Greek symbols in xtable rows

Roger Bivand Roger.Bivand at nhh.no
Sun Apr 29 21:29:29 CEST 2007


On Tue, 17 Apr 2007, James W. MacDonald wrote:

> Roger Bivand wrote:
> Andris Jankevics <andza <at> osi.lv> writes:
> 
> 
>>Thank You for answer. I Tried code that You provided in reply to my question 
>>on both PC's with Linux and Widows OS.
>>
> 
> Yes, I have also been bitten by the "upgrade" to xtable, which between 1.4-2 
> and 1.4-3 added code to try to be cleverer, but has broken output of LaTeX 
> markup directly. The offending code starts around line 177 in print.xtable.R 
> (#based on contribution from Jonathan Swinton <jonathan at swintons.net> in e-
> mail dated Wednesday, January 17, 2007). I did try to write a 
> sanitize.text.function= solution, but failed, and backed off to an earlier 
> version. Could the maintainer David Dahl, please address this, and include a 
> relevant test? (I would CC him, but am travelling and posting via gmane to keep 
> thr thread together - I apologize for pruning, but gmane won't post otherwise).
> 
> So a solution is to install an earlier version of xtable from the package 
> archives, a harder but feasible task for Windows.

The solution is to use a workable sanitize.text.function.

 > mat <- diag(c("$\\sigma_1^2$","$\\sigma_2^2$"))
 > tbl <- xtable(mat)
 > print.xtable(tbl, sanitize.text.function = function(x) x)
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Tue Apr 17 11:00:05 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
   \hline
  & 1 & 2 \\
   \hline
1 & $\sigma_1^2$ & 0 \\
   2 & 0 & $\sigma_2^2$ \\
    \hline
\end{tabular}
\end{center}
\end{table}
---------------------------------------
But (sorry for the long delay):

> mat <- diag(c("$\\sigma_1^2$","$\\sigma_2^2$"))
> colnames(mat) <- c("$\\sigma_1^2$","$\\sigma_2^2$")
> rownames(mat) <- c("$\\sigma_1^2$","$\\sigma_2^2$")
> tbl <- xtable(mat)
> print.xtable(tbl, sanitize.text.function = function(x) x)
% latex table generated in R 2.5.0 by xtable 1.4-3 package
% Sun Apr 29 21:24:18 2007
\begin{table}[ht]
\begin{center}
\begin{tabular}{rll}
  \hline
 & \$$\backslash$sigma\_1\verb|^|2\$ & \$$\backslash$sigma\_2\verb|^|2\$ 
\\
  \hline
$\sigma_1^2$ & $\sigma_1^2$ & 0 \\
  $\sigma_2^2$ & 0 & $\sigma_2^2$ \\
   \hline
\end{tabular}
\end{center}
\end{table}
> 

because sanitize() rather than sanitize.text.function() is used on the 
column names:

> sessionInfo()
R version 2.5.0 (2007-04-23) 
i686-pc-linux-gnu 

locale:
LC_CTYPE=en_GB;LC_NUMERIC=C;LC_TIME=en_GB;LC_COLLATE=en_GB;LC_MONETARY=en_GB;LC_MESSAGES=en_GB;LC_PAPER=en_GB;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB;LC_IDENTIFICATION=C

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"  
[7] "base"     

other attached packages:
     xtable       rgdal      lmtest         zoo       spdep      Matrix 
    "1.4-3"     "0.5-9"    "0.9-19"     "1.3-0"     "0.4-2" "0.9975-11" 
    lattice        boot    maptools     foreign          sp     tripack 
   "0.15-4"    "1.2-27"    "0.6-11"    "0.8-20"    "0.9-13"    "1.2-10" 

Roger

Best,

Jim




> 
> Roger
> 
> 
> ...
> 
> 
>>Thank You,
>>
>>Andris Jankevics
>>
>>On Pirmdiena, 16. Aprīlis 2007 22:38, Charles C. Berry wrote:
>>
>>>On Mon, 16 Apr 2007, Andris Jankevics wrote:
>>>
>>>
>>>>mat <- diag(c("$\\sigma_1^2$","$\\sigma_2^2$"))
>>>>xtable(mat)
>>>
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.


-- 
James W. MacDonald, M.S.
Biostatistician
Affymetrix and cDNA Microarray Core
University of Michigan Cancer Center
1500 E. Medical Center Drive
7410 CCGC
Ann Arbor MI 48109
734-647-5623

> 
> **********************************************************
> Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues.
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-help mailing list