Hao Zhu | 2a87e8e | 2017-06-14 15:49:33 -0400 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/collapse_rows.R |
| 3 | \name{collapse_rows} |
| 4 | \alias{collapse_rows} |
Hao Zhu | 8a160b1 | 2017-06-26 13:41:35 -1000 | [diff] [blame] | 5 | \title{Collapse repeated rows to multirow cell} |
Hao Zhu | 2a87e8e | 2017-06-14 15:49:33 -0400 | [diff] [blame] | 6 | \usage{ |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 7 | collapse_rows( |
| 8 | kable_input, |
| 9 | columns = NULL, |
| 10 | valign = c("middle", "top", "bottom"), |
Hao Zhu | 3e21ff9 | 2020-08-20 08:24:07 -0400 | [diff] [blame] | 11 | latex_hline = c("full", "major", "none", "custom", "linespace"), |
Kirill Müller | 64938ec | 2022-05-26 20:08:56 +0200 | [diff] [blame^] | 12 | row_group_label_position = c("identity", "stack", "first"), |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 13 | custom_latex_hline = NULL, |
| 14 | row_group_label_fonts = NULL, |
Hao Zhu | fdff6f4 | 2020-08-09 14:38:10 -0400 | [diff] [blame] | 15 | headers_to_remove = NULL, |
Hao Zhu | 2b739ac | 2020-08-15 01:38:51 -0400 | [diff] [blame] | 16 | target = NULL, |
| 17 | col_names = TRUE, |
| 18 | longtable_clean_cut = TRUE |
Hao Zhu | 9410a27 | 2020-08-03 01:11:47 -0400 | [diff] [blame] | 19 | ) |
Hao Zhu | 8a160b1 | 2017-06-26 13:41:35 -1000 | [diff] [blame] | 20 | } |
| 21 | \arguments{ |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 22 | \item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified} |
Hao Zhu | 8a160b1 | 2017-06-26 13:41:35 -1000 | [diff] [blame] | 23 | |
Jakob Richter | aebd829 | 2018-10-31 16:27:29 +0100 | [diff] [blame] | 24 | \item{columns}{A numeric value or vector indicating in which column(s) rows |
| 25 | need to be collapsed.} |
Hao Zhu | 53454f0 | 2018-01-14 16:29:10 -0500 | [diff] [blame] | 26 | |
Kirill Müller | 64938ec | 2022-05-26 20:08:56 +0200 | [diff] [blame^] | 27 | \item{valign}{Select from "top", "middle" (default), "bottom". The reason why |
Hao Zhu | ec16936 | 2018-05-21 01:05:29 -0400 | [diff] [blame] | 28 | "top" is not default is that the multirow package on CRAN win-builder is |
Kirill Müller | 64938ec | 2022-05-26 20:08:56 +0200 | [diff] [blame^] | 29 | not up to date. |
| 30 | Only used when \code{row_group_label_position} is \code{identity}.} |
Hao Zhu | be853f7 | 2018-05-20 18:52:26 -0400 | [diff] [blame] | 31 | |
Hao Zhu | 53454f0 | 2018-01-14 16:29:10 -0500 | [diff] [blame] | 32 | \item{latex_hline}{Option controlling the behavior of adding hlines to table. |
Hao Zhu | 3e21ff9 | 2020-08-20 08:24:07 -0400 | [diff] [blame] | 33 | Choose from \code{full}, \code{major}, \code{none}, \code{custom} and \code{linespace}.} |
Hao Zhu | 248bbef | 2018-04-02 18:25:14 -0400 | [diff] [blame] | 34 | |
| 35 | \item{row_group_label_position}{Option controlling positions of row group |
Kirill Müller | 64938ec | 2022-05-26 20:08:56 +0200 | [diff] [blame^] | 36 | labels. Choose from \code{identity}, \code{stack}, or \code{first} -- the latter behaves |
| 37 | like \code{identity} when \code{row_group_label_position} is \code{top} but without using |
| 38 | the multirow package.} |
Hao Zhu | 248bbef | 2018-04-02 18:25:14 -0400 | [diff] [blame] | 39 | |
| 40 | \item{custom_latex_hline}{Numeric column positions whose collapsed rows will |
| 41 | be separated by hlines.} |
| 42 | |
| 43 | \item{row_group_label_fonts}{A list of arguments that can be supplied to |
| 44 | group_rows function to format the row group label when |
Kirill Müller | 64938ec | 2022-05-26 20:08:56 +0200 | [diff] [blame^] | 45 | \code{row_group_label_position} is \code{stack}.} |
Hao Zhu | 248bbef | 2018-04-02 18:25:14 -0400 | [diff] [blame] | 46 | |
| 47 | \item{headers_to_remove}{Numeric column positions where headers should be |
| 48 | removed when they are stacked.} |
Hao Zhu | 2b739ac | 2020-08-15 01:38:51 -0400 | [diff] [blame] | 49 | |
| 50 | \item{target}{If multiple columns are selected to do collapsing and a target |
| 51 | column is specified, this target column will be used to collapse other |
| 52 | columns based on the groups of this target column.} |
| 53 | |
| 54 | \item{col_names}{T/F. A LaTeX specific option. If you set \code{col.names} be |
| 55 | \code{NULL} in your \code{kable} call, you need to set this option false to let |
| 56 | everything work properly.} |
| 57 | |
| 58 | \item{longtable_clean_cut}{T/F with default T. Multirow cell sometimes are |
| 59 | displayed incorrectly around pagebreak. This option forces groups to cut |
| 60 | before the end of a page. If you have a group that is longer than 1 page, |
| 61 | you need to turn off this option.} |
Hao Zhu | 2a87e8e | 2017-06-14 15:49:33 -0400 | [diff] [blame] | 62 | } |
| 63 | \description{ |
Hao Zhu | 8a160b1 | 2017-06-26 13:41:35 -1000 | [diff] [blame] | 64 | Collapse same values in columns into multirow cells. This |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 65 | feature does similar things with \code{group_rows}. However, unlike \code{group_rows}, |
Hao Zhu | 8a160b1 | 2017-06-26 13:41:35 -1000 | [diff] [blame] | 66 | it analyzes existing columns, finds out rows that can be grouped together, |
Hao Zhu | 76281fe | 2017-07-03 19:33:09 -0400 | [diff] [blame] | 67 | and make them multirow cells. Note that if you want to use \code{column_spec} to |
| 68 | specify column styles, you should use \code{column_spec} before \code{collapse_rows}. |
Hao Zhu | 2a87e8e | 2017-06-14 15:49:33 -0400 | [diff] [blame] | 69 | } |
Hao Zhu | 5a7689e | 2017-06-26 15:37:24 -1000 | [diff] [blame] | 70 | \examples{ |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame] | 71 | \dontrun{ |
Hao Zhu | 5a7689e | 2017-06-26 15:37:24 -1000 | [diff] [blame] | 72 | dt <- data.frame(a = c(1, 1, 2, 2), b = c("a", "a", "a", "b")) |
| 73 | x <- knitr::kable(dt, "html") |
| 74 | collapse_rows(x) |
Hao Zhu | 9399dcc | 2020-08-26 17:27:38 -0400 | [diff] [blame] | 75 | } |
Hao Zhu | 5a7689e | 2017-06-26 15:37:24 -1000 | [diff] [blame] | 76 | |
| 77 | } |