Home > OS >  How to obtain the Latex source code for table generated using Hmisc in R
How to obtain the Latex source code for table generated using Hmisc in R

Time:01-12

library(Hmisc)
options(digits=3)
set.seed(173)
sex <- factor(sample(c("m","f"), 500, rep=TRUE))
country <- factor(sample(c('US', 'Canada'), 500, rep=TRUE))
age <- rnorm(500, 50, 5)
sbp <- rnorm(500, 120, 12)
label(sbp) <- 'Systolic BP'
units(sbp) <- 'mmHg'
treatment <- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))
treatment[1]
sbp[1] <- NA

# Generate a 3-choice variable; each of 3 variables has 5 possible levels
symp <- c('Headache','Stomach Ache','Hangnail',
          'Muscle Ache','Depressed')
symptom1 <- sample(symp, 500,TRUE)
symptom2 <- sample(symp, 500,TRUE)
symptom3 <- sample(symp, 500,TRUE)
Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms')
table(as.character(Symptoms))

# Note: In this example, some subjects have the same symptom checked
# multiple times; in practice these redundant selections would be NAs
# mChoice will ignore these redundant selections

f <- summaryM(age   sex   sbp   Symptoms ~ treatment, test=TRUE)

In this example, how can I get the Latex code that's like what I would get if I were to use xtable() from the package xtable? I would like to get the source Latex code so I can add the table to another file.

I've tried

latex(f)

But that just shows the Latex table but does not give me the actual Latex code.

CodePudding user response:

Try:

latex(f, file="")

From ?Hmisc::latex: 'Set file="" to have the generated LaTeX code just printed to standard output.'

  • Related