2017-06-14 2 views
0

Ich versuche, eine FlexTable mit dem Reporter-Paket zu machen. Ich möchte flexibel festlegen können, ob für jede Spalte und Zeile mit cols.vertical und rows.vertical für alle ncol() + 1 Spaltengrenzen und alle nrow() - 1 Zeilenbegrenzungen Rahmen vorhanden sind. Außerdem möchte ich die dunkleren Ränder am oberen und unteren Rand der Tabelle einfügen können. Ein Beispiel für eine Spaltenspezifikation wird unten anhand des mtcars-Datasets gezeigt, und ein Beispiel für dunklere Grenzen wird mithilfe einer Teilmenge des Iris-Datasets gezeigt.Reporter Zellgrenzen

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)) 
+0

EIGÄNDR sein soll Wenn Sie eine Eigenschaft ändern, da in Ihrem Beispiel keine Eigenschaft angegeben ist, hat dies keine Auswirkungen. –

Antwort

0

Nicht sicher, dass es genau Ihre Frage beantwortet, aber Sie wenigstens etwas Code bekommen, mit dem Sie spielen können.

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

+0

Das "Formatierungseigenschaften-Objekt" in "chprop (a, Wert = bdr_2, ...)" ist bdr_2, nicht ein, korrekt? – Ben

+0

ja, chprop funktioniert auch mit FlexTable –

0

David Antwort war sehr hilfreich, das ist der Code, den ich zu verwenden, mit einiger Unsauberkeit am Ende Null zu ermöglichen, in cols.vertical

library(ReporteRs) 

bdr_1 <- borderSolid(width=1) 
bdr_2 <- borderSolid(width=2) 
a <- FlexTable(mtcars) 
a <- setFlexTableBorders(a, 
         inner.vertical = borderNone(), 
         inner.horizontal = borderNone(), 
         outer.vertical = borderNone(), 
         outer.horizontal = bdr_2, 
         body = TRUE, header = FALSE) 
a <- setFlexTableBorders(a, 
         inner.vertical = bdr_1, 
         inner.horizontal = bdr_1, 
         outer.vertical = borderNone(), 
         outer.horizontal = bdr_1, 
         body = FALSE, header = TRUE) 

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

a <- chprop(a, value = bdr_1, j = cols.vertical[cols.vertical>0], side = "right") 
a <- chprop(a, value = bdr_1, i = rows.horizontal, side = "bottom") 

if(0 %in% cols.vertical) { 
    if(1 %in% cols.vertical) { 
    a <- chprop(a, value = bdr_1, j = 1, side = "left") 
    a <- chprop(a, value = bdr_1, j = 1, side = "right") 
    } else { 
    a <- chprop(a, value = bdr_1, j = 1, side = "left") 
    } 
} 
a 
Verwandte Themen