[R] [Hmisc] Latex to pdf

Ista Zahn istazahn at gmail.com
Mon Sep 7 15:09:47 CEST 2009

Hi Jeroen,
> From: Jeroen Ooms <j.c.l.ooms at uu.nl>
> To: r-help at r-project.org
> Date: Sun, 6 Sep 2009 04:49:08 -0700 (PDT)
> Subject: [R] [Hmisc] Latex to pdf
> I would like to print some tables and figures to a PDF device on a CentOS 5
> vps. However, I cannot seem to get the latex function from Hmisc working. I
> followed the example, and got an error: sh: xdvi: command not found. I tried
> installing the 'tetex-xdvi' linux package, and now it returns: Error: Can't
> open display. I guess the reason for this is that the machine is a VPS
> terminal, so it has no display, however I dont understand why it does not
> write to the PDF device. Some code:

Yep, the VSP terminal is likely causing the problem.

> > pdf("test.pdf")

No, don't call latex() inside a pdf device like this. The latex()
command produces a .tex file, which can then be processed by the
system latex or pdflatex etc.

> > x <- matrix(1:6, nrow=2, dimnames=list(c('a','b'),c('c','d','this that')))
> > latex(x)   # creates x.tex in working directory

And what happens when you call "latex x.tex" from the system console
or system("latex x.tex") from R? Does it work? You can avoid having
the latex() function try to create and display the dvi by setting the
file name: latex(x, file="abcThisThat.tex").

Hope it helps,


Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology

> Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University
> Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
> current projects.

More information about the R-help mailing list