Add font_size option to row_spec; regenerate documentation
diff --git a/R/add_footnote.R b/R/add_footnote.R
index ce0a4a9..6bc04d7 100644
--- a/R/add_footnote.R
+++ b/R/add_footnote.R
@@ -1,10 +1,6 @@
#' Add footnote
#'
-#' @description Add footnote to your favorite kable output. So far this function
-#' only works when you define \code{format} in your kable function or in the
-#' global knitr option \code{knitr.table.format}. In latex, we are using the
-#' \code{threeparttable} package so you need to import this package in your
-#' \code{YAML} header.
+#' @description Add footnote to your favorite kable output.
#'
#' @param input The direct output of your \code{kable} function or your last
#' \code{kableExtra} function.
diff --git a/R/add_header_above.R b/R/add_header_above.R
index 62dd0e6..5439d75 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -2,8 +2,7 @@
#'
#' @description Tables with multiple rows of header rows are extremely useful
#' to demonstrate grouped data. This function takes the output of a `kable()`
-#' function and adds an header row on top of it. This function can work with
-#' both `HTML` and `LaTeX` outputs
+#' function and adds an header row on top of it.
#'
#' @param kable_input Output of `knitr::kable()` with `format` specified
#' @param header A (named) character vector with `colspan` as values. For
diff --git a/R/column_spec.R b/R/column_spec.R
index ffd23d5..8e0c554 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -1,8 +1,7 @@
#' Specify the look of the selected column
#'
#' @description This function allows users to select a column and then specify
-#' its look. Right now it supports the following three properties: column width,
-#' bold text and italic text.
+#' its look.
#'
#' @param kable_input Output of `knitr::kable()` with `format` specified
#' @param column A numeric value or vector indicating which column(s) to be selected.
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 8108fbb..4a3850c 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -1,8 +1,9 @@
#' HTML table attributes
#'
#' @description This function provides a cleaner approach to modify the style
-#' of HTML tables other than using the `table.attr` option in `knitr::kable()`.
-#' Currenly, it assumes the HTML document has boot
+#' of HTML tables other than using the `table.attr` option in `knitr::kable()`. Note
+#' that those bootstrap options requires Twitter bootstrap theme, which is not avaiable
+#' in some customized template being loaded.
#'
#' @param kable_input Output of `knitr::kable()` with `format` specified
#' @param bootstrap_options A character vector for bootstrap table options.
diff --git a/R/row_spec.R b/R/row_spec.R
index f45cb3d..19c5d00 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -19,6 +19,8 @@
#' @param align A character string for cell alignment. For HTML, possible values could
#' be `l`, `c`, `r` plus `left`, `center`, `right`, `justify`, `initial` and `inherit`
#' while for LaTeX, you can only choose from `l`, `c` & `r`.
+#' @param font_size Only if you want to specify font size locally in HTML. This feature
+#' is not available in LaTeX
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
#' row_spec(x, 1:2, bold = TRUE, italic = TRUE)
@@ -26,7 +28,7 @@
#' @export
row_spec <- function(kable_input, row,
bold = FALSE, italic = FALSE, monospace = FALSE,
- color = NULL, background = NULL, align = NULL) {
+ color = NULL, background = NULL, align = NULL, font_size = NULL) {
if (!is.numeric(row)) {
stop("row must be numeric. ")
}
@@ -37,7 +39,7 @@
}
if (kable_format == "html") {
return(row_spec_html(kable_input, row, bold, italic, monospace,
- color, background, align))
+ color, background, align, font_size))
}
if (kable_format == "latex") {
return(row_spec_latex(kable_input, row, bold, italic, monospace,
@@ -46,7 +48,7 @@
}
row_spec_html <- function(kable_input, row, bold, italic, monospace,
- color, background, align) {
+ color, background, align, font_size) {
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
@@ -61,7 +63,8 @@
original_header_row <- xml_child(kable_thead, length(xml_children(kable_thead)))
for (theader_i in 1:length(xml_children(original_header_row))) {
target_header_cell <- xml_child(original_header_row, theader_i)
- xml_cell_style(target_header_cell, bold, italic, monospace, color, background, align)
+ xml_cell_style(target_header_cell, bold, italic, monospace, color, background,
+ align, font_size)
}
row <- row[row != 0]
}
@@ -79,7 +82,8 @@
target_row <- xml_child(kable_tbody, j)
for (i in 1:length(xml_children(target_row))) {
target_cell <- xml_child(target_row, i)
- xml_cell_style(target_cell, bold, italic, monospace, color, background, align)
+ xml_cell_style(target_cell, bold, italic, monospace, color, background,
+ align, font_size)
}
}
}
@@ -89,7 +93,7 @@
return(out)
}
-xml_cell_style <- function(x, bold, italic, monospace, color, background, align) {
+xml_cell_style <- function(x, bold, italic, monospace, color, background, align, font_size) {
if (bold) {
xml_attr(x, "style") <- paste0(xml_attr(x, "style"),
"font-weight: bold;")
@@ -115,6 +119,10 @@
xml_attr(x, "style") <- paste0(xml_attr(x, "style"),
"text-align: ", align, ";")
}
+ if (!is.null(font_size)) {
+ xml_attr(x, "style") <- paste0(xml_attr(x, "style"),
+ "font-size: ", font_size, "px;")
+ }
return(x)
}
diff --git a/man/add_footnote.Rd b/man/add_footnote.Rd
index c46cf0d..46ab96e 100644
--- a/man/add_footnote.Rd
+++ b/man/add_footnote.Rd
@@ -25,11 +25,7 @@
Default is TRUE.}
}
\description{
-Add footnote to your favorite kable output. So far this function
-only works when you define \code{format} in your kable function or in the
-global knitr option \code{knitr.table.format}. In latex, we are using the
-\code{threeparttable} package so you need to import this package in your
-\code{YAML} header.
+Add footnote to your favorite kable output.
}
\examples{
x <- knitr::kable(head(mtcars), "html")
diff --git a/man/add_header_above.Rd b/man/add_header_above.Rd
index 6e3f214..80239fe 100644
--- a/man/add_header_above.Rd
+++ b/man/add_header_above.Rd
@@ -29,8 +29,7 @@
\description{
Tables with multiple rows of header rows are extremely useful
to demonstrate grouped data. This function takes the output of a \code{kable()}
-function and adds an header row on top of it. This function can work with
-both \code{HTML} and \code{LaTeX} outputs
+function and adds an header row on top of it.
}
\examples{
x <- knitr::kable(head(mtcars), "html")
diff --git a/man/column_spec.Rd b/man/column_spec.Rd
index ace0922..bbbd3a4 100644
--- a/man/column_spec.Rd
+++ b/man/column_spec.Rd
@@ -41,8 +41,7 @@
}
\description{
This function allows users to select a column and then specify
-its look. Right now it supports the following three properties: column width,
-bold text and italic text.
+its look.
}
\examples{
x <- knitr::kable(head(mtcars), "html")
diff --git a/man/kable_styling.Rd b/man/kable_styling.Rd
index 9c8e0de..5bf0ce4 100644
--- a/man/kable_styling.Rd
+++ b/man/kable_styling.Rd
@@ -49,8 +49,9 @@
}
\description{
This function provides a cleaner approach to modify the style
-of HTML tables other than using the \code{table.attr} option in \code{knitr::kable()}.
-Currenly, it assumes the HTML document has boot
+of HTML tables other than using the \code{table.attr} option in \code{knitr::kable()}. Note
+that those bootstrap options requires Twitter bootstrap theme, which is not avaiable
+in some customized template being loaded.
}
\details{
For LaTeX, extra options includes:
diff --git a/man/row_spec.Rd b/man/row_spec.Rd
index 4a94983..0ba6e0e 100644
--- a/man/row_spec.Rd
+++ b/man/row_spec.Rd
@@ -5,7 +5,8 @@
\title{Specify the look of the selected row}
\usage{
row_spec(kable_input, row, bold = FALSE, italic = FALSE,
- monospace = FALSE, color = NULL, background = NULL)
+ monospace = FALSE, color = NULL, background = NULL, align = NULL,
+ font_size = NULL)
}
\arguments{
\item{kable_input}{Output of \code{knitr::kable()} with \code{format} specified}
@@ -22,16 +23,22 @@
\item{monospace}{A T/F value to control whether the text of the selected column
need to be monospaced (verbatim)}
-\item{color}{A character string for column text color. Here please pay
+\item{color}{A character string for row text color. Here please pay
attention to the differences in color codes between HTML and LaTeX.}
-\item{background}{A character string for column background color. Here please
+\item{background}{A character string for row background color. Here please
pay attention to the differences in color codes between HTML and LaTeX.}
+
+\item{align}{A character string for cell alignment. For HTML, possible values could
+be \code{l}, \code{c}, \code{r} plus \code{left}, \code{center}, \code{right}, \code{justify}, \code{initial} and \code{inherit}
+while for LaTeX, you can only choose from \code{l}, \code{c} & \code{r}.}
+
+\item{font_size}{Only if you want to specify font size locally in HTML. This feature
+is not available in LaTeX}
}
\description{
This function allows users to select a row and then specify
-its look. Right now it supports the following two properties: bold text and
-italic text.
+its look. It can also specify the format of the header row when \code{row} = 0.
}
\examples{
x <- knitr::kable(head(mtcars), "html")
diff --git a/tests/visual_tests/column_row_spec_html.Rmd b/tests/visual_tests/column_row_spec_html.Rmd
index d84103a..e073930 100644
--- a/tests/visual_tests/column_row_spec_html.Rmd
+++ b/tests/visual_tests/column_row_spec_html.Rmd
@@ -54,6 +54,6 @@
kable(dt, "html") %>%
kable_styling(full_width = F) %>%
column_spec(7, bold = T) %>%
- row_spec(0, color = "black", align = "right") %>%
+ row_spec(0, color = "black", align = "right", font_size = 20) %>%
row_spec(5, bold = T, italic = T, color = "white", background = "black")
```