simplied some logics;
Added position offset to row_spec;
Adding @leovan to author list
diff --git a/DESCRIPTION b/DESCRIPTION
index 8d7bbdd..eba392d 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -14,7 +14,8 @@
person('Rob', 'Shepherd', role = 'ctb'),
person('Yoni', 'Sidi', role = 'ctb'),
person('Brian', 'Salzer', role = 'ctb'),
- person('George', 'Gui', role = 'ctb')
+ person('George', 'Gui', role = 'ctb'),
+ person('Yeliang', 'Fan', role = 'ctb')
)
Description: Build complex HTML or 'LaTeX' tables using 'kable()' from 'knitr'
and the piping syntax from 'magrittr'. Function 'kable()' is a light weight
@@ -31,7 +32,6 @@
Imports:
knitr (>= 1.16),
magrittr,
- stringi,
stringr (>= 1.0),
xml2,
rvest,
diff --git a/R/add_indent.R b/R/add_indent.R
index c0e1c1e..a8a455e 100644
--- a/R/add_indent.R
+++ b/R/add_indent.R
@@ -39,20 +39,14 @@
table_info <- dup_fx_out[[2]]
}
- if (table_info$booktabs & is.null(table_info$colnames)) {
- max_position <- table_info$nrow
- position_offset <- 0
- } else {
- max_position <- table_info$nrow - 1
- position_offset <- 1
- }
+ max_position <- table_info$nrow - table_info$position_offset
if (max(positions) > max_position) {
stop("There aren't that many rows in the table. Check positions in ",
"add_indent_latex.")
}
- for (i in positions + position_offset) {
+ for (i in positions + table_info$position_offset) {
rowtext <- table_info$contents[i]
out <- sub(rowtext, latex_indent_unit(rowtext), out, perl = TRUE)
table_info$contents[i] <- latex_indent_unit(rowtext)
diff --git a/R/group_rows.R b/R/group_rows.R
index d3871f7..4352105 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -163,11 +163,7 @@
if (italic) group_label <- paste0("\\\\textit{", group_label, "}")
# Add group label
if (table_info$booktabs) {
- if (is.null(table_info$colnames)) {
- rowtext <- table_info$contents[start_row]
- } else {
- rowtext <- table_info$contents[start_row + 1]
- }
+ rowtext <- table_info$contents[start_row + table_info$position_offset]
pre_rowtext <- paste0(
"\\\\addlinespace[", gap_space, "]\n",
ifelse(hline_before,"\\\\hline\n", ""),
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 67d8558..7b4b72b 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -55,7 +55,6 @@
#' vanilla rmarkdown. For customized rmarkdown templates, it is recommended to
#' load related LaTeX packages manually.
#'
-#' @importFrom stringi stri_replace_all_fixed
#' @importFrom stringr str_count str_split str_match str_detect str_match_all
#' str_extract str_replace_all str_trim str_extract_all str_sub str_replace
#' @importFrom xml2 read_xml xml_attr xml_has_attr xml_attr<- read_html
diff --git a/R/kable_styling.R b/R/kable_styling.R
index c80b3d5..75dd545 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -281,13 +281,10 @@
styling_latex_striped <- function(x, table_info, color) {
# gray!6 is the same as shadecolor ({RGB}{248, 248, 248}) in pdf_document
if (table_info$tabular == "longtable" & !is.na(table_info$caption)) {
- if (table_info$booktabs & is.null(table_info$colnames)) {
- row_color <- sprintf("\\rowcolors{1}{white}{%s}", color)
- } else {
- row_color <- sprintf("\\rowcolors{2}{white}{%s}", color)
- }
+ row_color <- sprintf("\\rowcolors{%s}{white}{%s}",
+ 1 + table_info$position_offset, color)
} else {
- if (table_info$booktabs & is.null(table_info$colnames)) {
+ if (table_info$position_offset == 0) {
row_color <- sprintf("\\rowcolors{1}{white}{%s}", color)
} else {
row_color <- sprintf("\\rowcolors{2}{%s}{white}", color)
diff --git a/R/magic_mirror.R b/R/magic_mirror.R
index 927aaec..5c2a942 100644
--- a/R/magic_mirror.R
+++ b/R/magic_mirror.R
@@ -90,14 +90,12 @@
}
kable_info$duplicated_rows <- (sum(duplicated(kable_info$contents)) != 0)
# Column names
- if (kable_info$booktabs) {
- if (is.na(which(read_lines(kable_input) == "\\midrule")[1])) {
- kable_info$colnames <- NULL
- } else {
- kable_info$colnames <- str_split(kable_info$contents[1], " \\& ")[[1]]
- }
+ if (kable_info$booktabs & !grepl("\\\\midrule", kable_input)) {
+ kable_info$colnames <- NULL
+ kable_info$position_offset <- 0
} else {
kable_info$colnames <- str_split(kable_info$contents[1], " \\& ")[[1]]
+ kable_info$position_offset <- 1
}
# Row names
kable_info$rownames <- str_extract(kable_info$contents, "^[^ &]*")
diff --git a/R/row_spec.R b/R/row_spec.R
index 76d7fbd..07962ed 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -187,7 +187,7 @@
table_info <- dup_fx_out[[2]]
}
- row <- row + 1
+ row <- row + table_info$position_offset
for (i in row) {
target_row <- table_info$contents[i]
new_row <- latex_new_row_builder(target_row, table_info,