Added auto_index
diff --git a/NAMESPACE b/NAMESPACE
index 49ada24..bdaf5ed 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -6,6 +6,7 @@
export(add_footnote)
export(add_header_above)
export(add_indent)
+export(auto_index)
export(cell_spec)
export(collapse_rows)
export(column_spec)
diff --git a/R/group_rows.R b/R/group_rows.R
index 4352105..f6f0d43 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -194,3 +194,19 @@
out <- add_indent_latex(out, seq(start_row, end_row))
return(out)
}
+
+#' Automatically figuring out the group_row index
+#'
+#' @description This helper function allows users to build the `group_row`
+#' index more quickly and use `group_rows` in a way that is similar with
+#' `collapse_rows`.
+#'
+#' @param x The index column. A vector. For example `c("a", "a", "b", "b", "b")``
+#'
+#' @export
+auto_index <- function(x) {
+ x_rle <- rle(x)
+ index <- x_rle$lengths
+ names(index) <- x_rle$values
+ return(index)
+}
diff --git a/inst/NEWS.md b/inst/NEWS.md
index 4d8479c..66fe15a 100644
--- a/inst/NEWS.md
+++ b/inst/NEWS.md
@@ -17,6 +17,8 @@
* Added valign to collapse_rows to adjust vertical position of the contents.
Change default setting from middle to top. (#191)
+* Added an auto_index function to facilitate group_rows. (#193)
+
kableExtra 0.8.0
--------------------------------------------------------------------------------
* Now kableExtra imports & exports knitr::kable so users don't need to load knitr entirely to NAMESPACE when it's not necessary, for example, in shiny.
@@ -259,7 +261,6 @@
* Fixed a few errors in the LaTeX vignette file.
-
kableExtra 0.1.0
--------------------------------------------------------------------------------
diff --git a/man/auto_index.Rd b/man/auto_index.Rd
new file mode 100644
index 0000000..abec3be
--- /dev/null
+++ b/man/auto_index.Rd
@@ -0,0 +1,16 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/group_rows.R
+\name{auto_index}
+\alias{auto_index}
+\title{Automatically figuring out the group_row index}
+\usage{
+auto_index(x)
+}
+\arguments{
+\item{x}{The index column. A vector. For example `c("a", "a", "b", "b", "b")``}
+}
+\description{
+This helper function allows users to build the \code{group_row}
+index more quickly and use \code{group_rows} in a way that is similar with
+\code{collapse_rows}.
+}
diff --git a/man/collapse_rows.Rd b/man/collapse_rows.Rd
index 49f9833..3609041 100644
--- a/man/collapse_rows.Rd
+++ b/man/collapse_rows.Rd
@@ -4,8 +4,9 @@
\alias{collapse_rows}
\title{Collapse repeated rows to multirow cell}
\usage{
-collapse_rows(kable_input, columns = NULL, latex_hline = c("full", "major",
- "none", "custom"), row_group_label_position = c("identity", "stack"),
+collapse_rows(kable_input, columns = NULL, valign = c("top", "middle",
+ "bottom"), latex_hline = c("full", "major", "none", "custom"),
+ row_group_label_position = c("identity", "stack"),
custom_latex_hline = NULL, row_group_label_fonts = NULL,
headers_to_remove = NULL)
}
@@ -14,6 +15,8 @@
\item{columns}{Numeric column positions where rows need to be collapsed.}
+\item{valign}{Select from "top"(default), "middle", "bottom"}
+
\item{latex_hline}{Option controlling the behavior of adding hlines to table.
Choose from \code{full}, \code{major}, \code{none}, \code{custom}.}