How to export HTML table to R and control line borders?

Are there any functions in R that allow you to export HTML tables as part of R Markdown or a linked woven document and that allow you to control the borders of the table in detail?

For example, imagine a matrix like this:

x <- matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE) 

which command will output the correct HTML table with the following functions:

  -------- MF --------------- Good 23 17 --------------- Bad 23 4 --------------- 
+4
source share
1 answer

You can try my really young package under heavy development called pander , which is trying to print R-objects in pandoc marking format.

Lazy example:

 > x <- matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE) > pandoc(x) +------+------+------+ | | M | F | +------+------+------+ | Good | 23 | 17 | +------+------+------+ | Bad | 23 | 4 | +------+------+------+ 

I'm just working on some functions, resulting in a different table syntax, such as a "simple table" or "multi-row table" (see Pandoc readme).


R. S .: you can also easily export this table to HTML (among other formats, such as docx, odt, etc.) with the Pandoc reference class (not documented):

 > myReport <- Pandoc$new() > myReport$add(x) > myReport Anonymous report ================== written by *Anonymous* at *Sun May 27 21:04:22 2012* This report holds 1 block(s). --- +------+------+------+ | | M | F | +------+------+------+ | Good | 23 | 17 | +------+------+------+ | Bad | 23 | 4 | +------+------+------+ --- Proc. time: 0.009 seconds. > myReport$format <- 'html' > myReport$export() Exported to */tmp/pander-4e9c12ff63a6.[md|html]* under 0.031 seconds. 

PS secondly: you can also brew (e.g. sweave) a text document with Pandoc.brew , which automatically converts the tags <%=...%> from internal R to the Pandoc markdown format. A short example (of course, this will also work with file input, now I just brew the character vector R):

 > t <- '# Title + + A nice matrix: + + <%=matrix(c("", "M", "F", "Good", "23", "17", "Bad", "23", "4"), nrow=3, byrow=TRUE)%> + + Bye-bye!' > > Pandoc.brew(text=t) # Title A nice matrix: +------+------+------+ | | M | F | +------+------+------+ | Good | 23 | 17 | +------+------+------+ | Bad | 23 | 4 | +------+------+------+ Bye-bye! 
+9
source

Source: https://habr.com/ru/post/1414594/


All Articles