Ben Ben -3 years ago 100
R Question

ReporteRs Cell Borders

I am trying to make a FlexTable using the ReporteRs package. I want to be able to flexibly specify whether borders exist for each column and row using cols.vertical and rows.vertical, for all ncol()+ 1 column borders and all nrow() - 1 row borders. Additionally, I would like to be able to include the darker borders at the top and bottom of the border of the table. An example of column specification is shown below using the mtcars dataset, and an example of darker borders is shown using a subset of the iris dataset.

library(ReporteRs)

a <- FlexTable(mtcars, body.cell.props = cellProperties(border.style = "none"))

cols.vertical <- c(2, 4, 5)
rows.horizontal <- c(3, 4, 7)

a[, cols.vertical] <- chprop(cellProperties(border.right.width = 1,
border.left.width=0,
border.top.width=0,
border.bottom.width=0))
a[rows.horizontal, ] <- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=0,
border.bottom.width=1))
a[rows.horizontal, cols.vertical] <- chprop(cellProperties(border.right.width=1,
border.left.width=0,
border.top.width=0,
border.bottom.width=1))

b <- FlexTable(iris[1:10,], body.cell.props = cellProperties(border.style="none"))
b[1, ]<- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=2,
border.bottom.width=0))
b[nrow(iris[1:10, ]), ] <- chprop(cellProperties(border.right.width = 0,
border.left.width=0,
border.top.width=0,
border.bottom.width=2))

Answer Source

Not sure it answers exactly your question but at least you will get some code to play with.

library(ReporteRs)

bdr_1 <- borderSolid(width=2, color="gray")
bdr_2 <- chprop(bdr_1, color="orange")
a <- FlexTable(mtcars)
a <- setFlexTableBorders(a, 
                         inner.vertical = borderNone(), inner.horizontal = borderNone(), 
                         outer.vertical = bdr_1,
                         outer.horizontal = bdr_1,
                         body = TRUE, header = TRUE)

cols.vertical <- c(2, 4, 5)
rows.horizontal <- c(3, 4, 7)

a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "left")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "right")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "top")
a <- chprop(a, value = bdr_2, i = rows.horizontal, j = cols.vertical, side = "bottom")
a

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download