[R] Printing localized pdf file from Sweave snippets

Duncan Murdoch murdoch.duncan at gmail.com
Fri Sep 14 14:17:50 CEST 2012


On 14/09/2012 7:07 AM, Petar Milin wrote:
> Hello!
> I am struggling for quite some time with proper printing of local
> characters in pdf plot, via Sweave snippets in Rnw file.
>
> When I am working directly within R, all is fine and I can get local
> character properly, like:
> pdf('figs/fig-relativeEntropy0.pdf', h=6, w=6, encoding='CP1250')
> matplot(par[, c(3)], type='b', ylim=c(0,0.5), xaxt='n', pch=c(21),
> 	lty=c('dashed'), lwd=c(3), xlab='', ylab='')
> 	axis(1, at=1:6, labels=as.character(par$suffix), cex.axis=1.2)
> 	legend(2, 0.48, 'pučina (open-sea)', bty='n', cex=1.2)
> dev.off()
>
> However, in Rnw file, I made an preamble line:
> \usepackage{Sweave}
> \usepackage[cp1250]{inputenc}
>
> >From this, I am getting dots. Also, I tried to play with the:
> pdf.options(encoding='CP1250')
> within the Sweave snippet. No luck at all!
>
> Please, is there a straightforward solution?!?
>
> I read two links, but no sign of correct how-to:
> http://stackoverflow.com/questions/3434349/sweave-not-printing-localized-characters
> http://r.789695.n4.nabble.com/Problems-with-Sweave-and-pdf-options-encoding-quot-ISOLatin7-quot-PR-13234-td921653.html

This isn't really an answer to your question, but it might be a 
workaround:  switch to the UTF-8 encoding.  It is the default on many 
systems (e.g. most Unix-alikes these days), so it is probably better 
supported internally.  You might need to convert your string to UTF8; 
you can do that by replacing

'pučina (open-sea)'


with

'pu\u010dina (open-sea)'

Duncan Murdoch




More information about the R-help mailing list