[R] new to latex to pdf

Mike Babyak mbabyak at nc.rr.com
Sun Mar 2 19:51:01 CET 2008


Dear All,

I'm trying to teach myself latex along with the latex function in Hmisc 
and have hit a roadblock that I can't seem to get around. I'd greatly 
appreciate any pointers.

I'm running R 2.6.0 on Windows XP and have Miktex 2.7 installed. 

I've reproduced the code below, taken from Frank Harrell's latexsummary 
introduction.  My question relates to getting a pdf version of the table 
from the following code.  The pdfs of the graphics (f1a and f1b) 
generated by setpdf are fine.  However, after a number of attempts using 
different methods, I don't seem to be able to get a pdf of the table 
from the s1 object (I see the right table in my previewer just fine).  
I've tried texi2dvi (texfilename, pdf=T) but get only a series of errors 
and an unformatted table in the pdf. 

I'm sure I'm missing some fundamental concept here, but I'm afraid I'm 
not seeing it.  I'd appreciate if anyone could point me in the right 
direction. ( I have no trouble writing my own simple latex code and 
converting it to pdf using pdftex in miktex).

Thanks,

Mike Babyak
Department of Psychiatry and Behavioral Science
Duke University Medical Center

**************************
Here's the code:

library(Hmisc)
library(survival)
 
getHdata(pbc)
pbc<-upData(pbc, moveUnits=TRUE,
labels=c(stage='Histologic Stage\nLudwig Criteria'))

kmsurv <- function(S, times) {
f <- survfit.km(factor(rep(1,nrow(S))), S)
tt <- c(0, f$time)
ss <- c(1, f$surv) # add first point to survival curve
approx(tt, ss, xout=times, method='constant', f=0)$y
}
 
describe.survival <- function(y) {
km <- kmsurv(y, c(2,5))
c('2 Year'=km[1], '5 Year'=km[2], 'Mean, y'=sum(y[,1])/sum(y[,2]))
}

S <- with(pbc, Surv(fu.days/365.25, status))
s1 <- summary(S ~ age + albumin + ascites + bili + drug + edema + chol,
fun=describe.survival, data=pbc)
 
for(w in 1:2) {
if(w==1) setpdf(f1a,sublines=1,h=5.25) else
setpdf(f1b,sublines=1,h=5)
plot(s1, which=if(w==1)1:2 else 3,
cex.labels=.7, cex.group.labels=.7*1.15, subtitles=T, main='',
pch=if(w==2) 16 else c('2','5'), # 16=solid circle
xlab=if(w==2)'Survival Time' else 'Survival Probability')
dev.off()
}

w <- latex(s1, cdec=c(2,2,1), ctable=TRUE, caption='Survival')



More information about the R-help mailing list