blob: 8efcb55637f5509d44ebe1919aa9480c46f029e1 [file] [log] [blame]
Hao Zhu2a87e8e2017-06-14 15:49:33 -04001% 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 Zhu8a160b12017-06-26 13:41:35 -10005\title{Collapse repeated rows to multirow cell}
Hao Zhu2a87e8e2017-06-14 15:49:33 -04006\usage{
Hao Zhu9410a272020-08-03 01:11:47 -04007collapse_rows(
8 kable_input,
9 columns = NULL,
10 valign = c("middle", "top", "bottom"),
Hao Zhu3e21ff92020-08-20 08:24:07 -040011 latex_hline = c("full", "major", "none", "custom", "linespace"),
Hao Zhube853f72018-05-20 18:52:26 -040012 row_group_label_position = c("identity", "stack"),
Hao Zhu9410a272020-08-03 01:11:47 -040013 custom_latex_hline = NULL,
14 row_group_label_fonts = NULL,
Hao Zhufdff6f42020-08-09 14:38:10 -040015 headers_to_remove = NULL,
Hao Zhu2b739ac2020-08-15 01:38:51 -040016 target = NULL,
17 col_names = TRUE,
18 longtable_clean_cut = TRUE
Hao Zhu9410a272020-08-03 01:11:47 -040019)
Hao Zhu8a160b12017-06-26 13:41:35 -100020}
21\arguments{
Hao Zhu76281fe2017-07-03 19:33:09 -040022\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
Hao Zhu8a160b12017-06-26 13:41:35 -100023
Jakob Richteraebd8292018-10-31 16:27:29 +010024\item{columns}{A numeric value or vector indicating in which column(s) rows
25need to be collapsed.}
Hao Zhu53454f02018-01-14 16:29:10 -050026
Hao Zhuec169362018-05-21 01:05:29 -040027\item{valign}{Select from "top", "middle"(default), "bottom". The reason why
28"top" is not default is that the multirow package on CRAN win-builder is
29not up to date.}
Hao Zhube853f72018-05-20 18:52:26 -040030
Hao Zhu53454f02018-01-14 16:29:10 -050031\item{latex_hline}{Option controlling the behavior of adding hlines to table.
Hao Zhu3e21ff92020-08-20 08:24:07 -040032Choose from \code{full}, \code{major}, \code{none}, \code{custom} and \code{linespace}.}
Hao Zhu248bbef2018-04-02 18:25:14 -040033
34\item{row_group_label_position}{Option controlling positions of row group
35labels. Choose from \code{identity}, \code{stack}.}
36
37\item{custom_latex_hline}{Numeric column positions whose collapsed rows will
38be separated by hlines.}
39
40\item{row_group_label_fonts}{A list of arguments that can be supplied to
41group_rows function to format the row group label when
42\code{row_group_label_position} is \code{stack}}
43
44\item{headers_to_remove}{Numeric column positions where headers should be
45removed when they are stacked.}
Hao Zhu2b739ac2020-08-15 01:38:51 -040046
47\item{target}{If multiple columns are selected to do collapsing and a target
48column is specified, this target column will be used to collapse other
49columns based on the groups of this target column.}
50
51\item{col_names}{T/F. A LaTeX specific option. If you set \code{col.names} be
52\code{NULL} in your \code{kable} call, you need to set this option false to let
53everything work properly.}
54
55\item{longtable_clean_cut}{T/F with default T. Multirow cell sometimes are
56displayed incorrectly around pagebreak. This option forces groups to cut
57before the end of a page. If you have a group that is longer than 1 page,
58you need to turn off this option.}
Hao Zhu2a87e8e2017-06-14 15:49:33 -040059}
60\description{
Hao Zhu8a160b12017-06-26 13:41:35 -100061Collapse same values in columns into multirow cells. This
Hao Zhu76281fe2017-07-03 19:33:09 -040062feature does similar things with \code{group_rows}. However, unlike \code{group_rows},
Hao Zhu8a160b12017-06-26 13:41:35 -100063it analyzes existing columns, finds out rows that can be grouped together,
Hao Zhu76281fe2017-07-03 19:33:09 -040064and make them multirow cells. Note that if you want to use \code{column_spec} to
65specify column styles, you should use \code{column_spec} before \code{collapse_rows}.
Hao Zhu2a87e8e2017-06-14 15:49:33 -040066}
Hao Zhu5a7689e2017-06-26 15:37:24 -100067\examples{
Hao Zhu9399dcc2020-08-26 17:27:38 -040068\dontrun{
Hao Zhu5a7689e2017-06-26 15:37:24 -100069dt <- data.frame(a = c(1, 1, 2, 2), b = c("a", "a", "a", "b"))
70x <- knitr::kable(dt, "html")
71collapse_rows(x)
Hao Zhu9399dcc2020-08-26 17:27:38 -040072}
Hao Zhu5a7689e2017-06-26 15:37:24 -100073
74}