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)
}