removed duplicated code and updated news
diff --git a/R/add_header_above.R b/R/add_header_above.R
index 6beb5a0..9582577 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -11,7 +11,7 @@
#' convenience, when `colspan` equals to 1, users can drop the ` = 1` part.
#' As a result, `c(" ", "title" = 2)` is the same as `c(" " = 1, "title" = 2)`.
#' Alternatively, a data frame with two columns can be provided: The first
-#' column should contain the header names (character vector) and the second
+#' column should contain the header names (character vector) and the second
#' column should contain the colspan (numeric vector). This input can be used
#' if there are problems with unicode characters in the headers.
#' @param bold A T/F value to control whether the text should be bolded.
@@ -69,6 +69,23 @@
"for details.")
return(kable_input)
}
+ if (is.null(header)) return(kable_input)
+ if (is.data.frame(header)){
+ if(ncol(header) == 2 & is.character(header[[1]]) & is.numeric(header[[2]])){
+ header <- data.frame(header = header[[1]], colspan = header[[2]],
+ stringsAsFactors = FALSE)
+ }
+ else {
+ stop("If header input is provided as a data frame instead of a named",
+ "vector it must consist of only two columns: ",
+ "The first should be a character vector with ",
+ "header names and the second should be a numeric vector with ",
+ "the number of columns the header should span.")
+ }
+ }
+ else {
+ header <- standardize_header_input(header)
+ }
if (kable_format == "html") {
return(htmlTable_add_header_above(
kable_input, header, bold, italic, monospace, underline, strikeout,
@@ -90,29 +107,10 @@
align, color, background, font_size,
angle, escape, line, line_sep,
extra_css, include_empty) {
- if (is.null(header)) return(kable_input)
-
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
kable_xml_thead <- xml_tpart(kable_xml, "thead")
-
- if (is.data.frame(header)){
- if(ncol(header) == 2 & is.character(header[[1]]) & is.numeric(header[[2]])){
- header <- data.frame(header = header[[1]], colspan = header[[2]],
- stringsAsFactors = FALSE)
- }
- else {
- stop("If header input is provided as a data frame instead of a named vector ",
- "it must consist of only two columns: ",
- "The first should be a character vector with ",
- "header names and the second should be a numeric vector with ",
- "the number of columns the header should span.")
- }
- }
- else {
- header <- standardize_header_input(header)
- }
-
+
if (escape) {
header$header <- escape_html(header$header)
}
@@ -236,7 +234,7 @@
escape, line, line_sep,
border_left, border_right) {
table_info <- magic_mirror(kable_input)
-
+
if (is.data.frame(header)){
if(ncol(header) == 2 & is.character(header[[1]]) & is.numeric(header[[2]])){
header <- data.frame(header = header[[1]], colspan = header[[2]],