EDIT I found the answer and posted below. The only reason I had thought it was working in math mode was because I was running an example and never saw the sanitize-text-function
argument was being passed to the print method. I'll accept this answer once it becomes available.
I am typesetting a manuscript and doing a data analysis for it. In this analysis, I'm generating a table 1 and looking to indent some row names in the table to give it a cascading feel.
An example of the data I have is:
require(xtable)
data <- data.frame(
'case'=sample(c('case', 'control'), 100, replace=TRUE),
'age'=sample(c('40-50,', '50-60', '60-70'), 100, replace=TRUE),
'sex'=sample(c('male', 'female'), 100, replace=TRUE),
'income'=sample(c('under 50,000', '50-100,000', 'over 10000'), 100, replace=TRUE)
)
tables <- lapply(data[, -1], table, data[, 1])
tables <- lapply(tables, function(x) {
rownames(x) <- paste('\\hspace{5mm}', rownames(x))
x
})
tablenames <- names(tables)
tables <- Reduce(rbind, mapply(rbind, '', tables))
rownames(tables)[rownames(tables) == ''] <- tablenames
xtable(tables)
xtable(tables, type='latex', sanitize.text.function=identity)
I understand the last two xtable commands should return different tables. I'm using the most recent version of R and xtable.
Welp... Apparently, sanitize.text.function
is an argument to print.xtable
and not to xtable
itself. Doing
print(xtable(tables), type='latex', sanitize.text.function=identity)
solves the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With