Re: [R] Export to LaTeX

From: Dieter Menne <>
Date: Fri 14 Jul 2006 - 19:06:19 EST

Mag. Ferri Leberl <ferri.leberl <at>> writes:

> I want to export data to LaTeX. As I want to employ the data as freely as
> possible I want to avoid the xtable-command and instead generate some List
> like
> \MyOwnPrettyCommand{Adam}{Auer}{17}
> \MyOwnPrettyCommand{Bertram}{Bauer}{14}
> \MyOwnPrettyCommand{Christoph}{Huber}{75}
> with \MyOwnPrittyCommand defined elsewhere.

Method 1: Use latex in package Hmisc. It is VERY flexible, and works for me in most cases.

Hint 1: "\" rarely works in R as in C, it must be escaped to "\\"

Hint 2: To increase you changes of getting a reply, always provide a full example generating the sample data. For example, in most cases "Adam" will be stored as a factor in the dataframe, which make things a bit more tricky. I used I() to avoid this in the example below

d = data.frame(name=I(c("Auer","Caesar")),

               vname=I(c("Dieter","Karl")),age=c(10,30)) for (i in 1:nrow(d)) {
  d0 = d[i,]
  cat("\\MyNiceCommand{",d0$name,"}{",d0$vname,"}{",d0$age,"}\n",sep="") }

You may nest this with sink, or better use the file argument in cat, don't forget append.
Or directly use Rweave, which should not be too difficult for a LaTeXer, and does not require the sink stuff.

Dieter mailing list PLEASE do read the posting guide! Received on Fri Jul 14 19:14:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 14 Jul 2006 - 20:14:51 EST.

Mailing list information is available at Please read the posting guide before posting to the list.