Hmisc tilde rowname

I am trying to group row names in a R data frame for typesetting with the Hmisc latex() function. Problem is that latex() adds two tilde characters before each row name, and these show up in my document.

How can I either remove these characters or have them not show up?

Example:

test.df <- data.frame(row.names=letters[1:4],   col1=1:4, col2=4:1, col3=4:7)
latex(test.df, file="", n.rgroup=c(2,2), rgroup=c("First","Second"))

Edit: The latex function occurs inside a knitr chunk. The resulting .Rnw file is compiled through the knit2pdf function, which uses pdfLatex by default, I think. All other tables/figures in the document compile fine, without any residual LaTex syntax showing up.


They will not show up if you use latex with a TeX processor:

test.df <- data.frame(row.names=letters[1:4],   col1=1:4, col2=4:1, col3=4:7)
latex(test.df, file="test", n.rgroup=c(2,2), rgroup=c("First","Second"))

If you want to "capture" the text that is "printed" to the screen and remove the double tildes with sub then you probably need to use capture.output , because it appears that latex is not returning a value but is acting more like the cat function which has output to the screen as a side-effect:

out <- sub("^~~", "", capture.output( 
                     latex(test.df, file="", 
                         n.rgroup=c(2,2), rgroup=c("First","Second")))) 

You could then use writeLines or cat with a file argument to send that text to a destination. I suppose it is possible that you could just put the sub call inline without diverting the results to a named object. That will depend on exactly how your are processing this text.


If you don't want to use LaTeX then i suggest either the ascii package that has pretty advanced options that do a nice raw text output (it also has the rgroup & n.rgroup options for grouping row names). If you are interested in getting the tables into a Word document (or just HTML) i suggest Markdown with my htmlTable function - the arguments are based upon the Hmisc latex arguments as I needed a replacement when I was switching to Markdown, thus all you need to do is change the function name to htmlTable after loading my package.

链接地址: http://www.djcxy.com/p/96260.html

上一篇: R rownames(foo [bar])打印为空,但可以成功更改

下一篇: Hmisc tilde rowname