table.rows: Convert to HTML table rows.

Description Usage Arguments Value Functions Examples

View source: R/table1.R

Description

Many functions exist in R to generate HTML tables. These functions are useful for generating HTML table fragments (rather than whole tables), which can then be used to build up complete tables. The first column my be used to label the rows of the table. Row labels, if specified, can have a special HTML class designated, which can be useful as a hook to customize their appearance using CSS. The same is true for the the first and last row of cells.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
table.rows(
  x,
  row.labels = rownames(x),
  th = FALSE,
  class = NULL,
  rowlabelclass = "rowlabel",
  firstrowclass = "firstrow",
  lastrowclass = "lastrow",
  ...
)

table.data(
  x,
  row.labels = rownames(x),
  th = FALSE,
  class = NULL,
  rowlabelclass = "rowlabel",
  firstrowclass = "firstrow",
  lastrowclass = "lastrow",
  ...
)

Arguments

x

A vector or table-like structure (e.g. a data.frame or matrix).

row.labels

Values for the first column, typically used to label the row, or NULL to omit.

th

A logical. Should th tags be used rather than td?

class

HTML class attribute. Can be a single character, a vector or a matrix.

rowlabelclass

HTML class attribute for the row labels (i.e. first column).

firstrowclass

HTML class attribute for the first row of cells.

lastrowclass

HTML class attribute for the last row of cells.

...

Additional arguments.

Value

A character which contains an HTML table fragment.

Functions

Examples

1
2
3
4
5
x <- matrix(signif_pad(exp(rnorm(5*5, 1, 1))), 5, 5)
table.data(x)
cat(table.rows(x, NULL))
cat(table.rows(x, LETTERS[1:nrow(x)]))
cat(table.rows(LETTERS[1:3], "Headings", th=TRUE))

Example output

Attaching package:table1The following objects are masked frompackage:base:

    units, units<-

[1] "<td class='firstrow'>3.42</td>\n<td class='firstrow'>5.89</td>\n<td class='firstrow'>1.24</td>\n<td class='firstrow'>3.00</td>\n<td class='firstrow'>4.39</td>"
[2] "<td>1.21</td>\n<td>3.69</td>\n<td>7.29</td>\n<td>1.65</td>\n<td>0.993</td>"                                                                                    
[3] "<td>3.98</td>\n<td>1.51</td>\n<td>13.3</td>\n<td>8.37</td>\n<td>3.11</td>"                                                                                     
[4] "<td>12.3</td>\n<td>7.57</td>\n<td>2.76</td>\n<td>2.10</td>\n<td>0.455</td>"                                                                                    
[5] "<td class='lastrow'>1.94</td>\n<td class='lastrow'>18.8</td>\n<td class='lastrow'>3.29</td>\n<td class='lastrow'>10.7</td>\n<td class='lastrow'>15.3</td>"     
<tr>
<td class='rowlabel firstrow'></td>
<td class='firstrow'>3.42</td>
<td class='firstrow'>5.89</td>
<td class='firstrow'>1.24</td>
<td class='firstrow'>3.00</td>
<td class='firstrow'>4.39</td>
</tr>
<tr>
<td class='rowlabel'></td>
<td>1.21</td>
<td>3.69</td>
<td>7.29</td>
<td>1.65</td>
<td>0.993</td>
</tr>
<tr>
<td class='rowlabel'></td>
<td>3.98</td>
<td>1.51</td>
<td>13.3</td>
<td>8.37</td>
<td>3.11</td>
</tr>
<tr>
<td class='rowlabel'></td>
<td>12.3</td>
<td>7.57</td>
<td>2.76</td>
<td>2.10</td>
<td>0.455</td>
</tr>
<tr>
<td class='rowlabel lastrow'></td>
<td class='lastrow'>1.94</td>
<td class='lastrow'>18.8</td>
<td class='lastrow'>3.29</td>
<td class='lastrow'>10.7</td>
<td class='lastrow'>15.3</td>
</tr>
<tr>
<td class='rowlabel firstrow'>A</td>
<td class='firstrow'>3.42</td>
<td class='firstrow'>5.89</td>
<td class='firstrow'>1.24</td>
<td class='firstrow'>3.00</td>
<td class='firstrow'>4.39</td>
</tr>
<tr>
<td class='rowlabel'>B</td>
<td>1.21</td>
<td>3.69</td>
<td>7.29</td>
<td>1.65</td>
<td>0.993</td>
</tr>
<tr>
<td class='rowlabel'>C</td>
<td>3.98</td>
<td>1.51</td>
<td>13.3</td>
<td>8.37</td>
<td>3.11</td>
</tr>
<tr>
<td class='rowlabel'>D</td>
<td>12.3</td>
<td>7.57</td>
<td>2.76</td>
<td>2.10</td>
<td>0.455</td>
</tr>
<tr>
<td class='rowlabel lastrow'>E</td>
<td class='lastrow'>1.94</td>
<td class='lastrow'>18.8</td>
<td class='lastrow'>3.29</td>
<td class='lastrow'>10.7</td>
<td class='lastrow'>15.3</td>
</tr>
<tr>
<th class='rowlabel firstrow lastrow'>Headings</th>
<th class='firstrow lastrow'>A</th>
<th class='firstrow lastrow'>B</th>
<th class='firstrow lastrow'>C</th>
</tr>

table1 documentation built on June 7, 2021, 1:07 a.m.