[R] Sweave'ing Danish characters

Peter Jepsen PJ at DCE.AU.DK
Mon Jan 26 23:44:33 CET 2009


Hi,

I am writing an Sweave document and am using 'xtable' to make frequency tables of diagnoses of people undergoing cholecystectomy. Some of these diagnoses contain Danish characters ("æ", "ø", and "å"), and these characters are all garbled in the Latex document after I run Sweave. The odd thing is, everything looks absolutely right in the R console, and if I enter the same Danish characters in a new variable, the new variable produces no problems?! Therefore, I cannot offer a reproducible example, but I am hoping nonetheless that someone can point me towards a solution.

To illustrate:

> library(xtable)
> library(Hmisc)
> rm(list=ls())
> load("u:/kirurgi/cholecystit/Chol_oprenset.Rdata")
> 	
> test2 <- chol$nydiag[3]	# This 3rd observation contains a diagnosis with Danish characters ("Kræft i fordøjelsessystemet", meaning gastrointestinal cancer).
> 
> print(xtable(table(test2)))
% latex table generated in R 2.8.1 by xtable 1.5-4 package
% Mon Jan 26 23:31:37 2009
\begin{table}[ht]
\begin{center}
\begin{tabular}{rr}
  \hline
 & test2 \\
  \hline
Kræft i fordøjelsessystemet &   1 \\	# It looks right here, but in the .tex-file it says "Kræft i fordøjelsessystemet"
   \hline
\end{tabular}
\end{center}
\end{table}

> print(xtable(table("Kræft i fordøjelsessystemet")))	# This, on the other hand, works like a charm.
% latex table generated in R 2.8.1 by xtable 1.5-4 package
% Mon Jan 26 23:36:53 2009
\begin{table}[ht]
\begin{center}
\begin{tabular}{rr}
  \hline
 & V1 \\
  \hline
Kræft i fordøjelsessystemet &   1 \\	# See, no problems here!
   \hline
\end{tabular}
\end{center}
\end{table}


I am using Windows Vista 64-bit and MikTex 2.7. 

Best regards,
Peter.

> sessionInfo()
R version 2.8.1 (2008-12-22) 
i386-pc-mingw32 

locale:
LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252

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

other attached packages:
[1] Hmisc_3.4-4    foreign_0.8-30 xtable_1.5-4  

loaded via a namespace (and not attached):
[1] cluster_1.11.12 grid_2.8.1      lattice_0.17-20 tools_2.8.1




More information about the R-help mailing list