Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extra_latex_before to row_spec function #702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export(row_spec)
export(save_kable)
export(scroll_box)
export(spec_angle)
export(spec_barplot)
export(spec_boxplot)
export(spec_color)
export(spec_font_size)
Expand Down
52 changes: 30 additions & 22 deletions R/row_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#' addes a hline after ther row
#' @param extra_latex_after Extra LaTeX text to be added after the row. Similar
#' with `add.to.row` in xtable
#' @param extra_latex_before Extra LaTeX text to be added before the row.
#'
#' @examples
#' \dontrun{
Expand All @@ -46,7 +47,7 @@ row_spec <- function(kable_input, row,
underline = FALSE, strikeout = FALSE,
color = NULL, background = NULL, align = NULL,
font_size = NULL, angle = NULL, extra_css = NULL,
hline_after = FALSE, extra_latex_after = NULL) {
hline_after = FALSE, extra_latex_after = NULL, extra_latex_before = NULL) {
if (!is.numeric(row)) {
stop("row must be numeric. ")
}
Expand All @@ -67,7 +68,7 @@ row_spec <- function(kable_input, row,
return(row_spec_latex(kable_input, row, bold, italic, monospace,
underline, strikeout,
color, background, align, font_size, angle,
hline_after, extra_latex_after))
hline_after, extra_latex_after, extra_latex_before))
}
}

Expand Down Expand Up @@ -183,7 +184,7 @@ xml_cell_style <- function(x, bold, italic, monospace,
row_spec_latex <- function(kable_input, row, bold, italic, monospace,
underline, strikeout,
color, background, align, font_size, angle,
hline_after, extra_latex_after) {
hline_after, extra_latex_after, extra_latex_before) {
table_info <- magic_mirror(kable_input)
out <- solve_enc(kable_input)

Expand All @@ -200,7 +201,8 @@ row_spec_latex <- function(kable_input, row, bold, italic, monospace,
bold, italic, monospace,
underline, strikeout,
color, background, align, font_size, angle,
hline_after, extra_latex_after)
hline_after, extra_latex_after, extra_latex_before)

temp_sub <- ifelse(i == 1 & (table_info$tabular == "longtable" |
!is.null(table_info$repeat_header_latex)),
gsub, sub)
Expand All @@ -211,7 +213,7 @@ row_spec_latex <- function(kable_input, row, bold, italic, monospace,
} else {
out <- temp_sub(paste0(target_row, "\\\\\\\\"),
paste(new_row, collapse = ""), out, perl = T)
table_info$contents[i] <- new_row[1]
table_info$contents[i] <- new_row[2]
}
}

Expand All @@ -224,7 +226,7 @@ latex_new_row_builder <- function(target_row, table_info,
bold, italic, monospace,
underline, strikeout,
color, background, align, font_size, angle,
hline_after, extra_latex_after) {
hline_after, extra_latex_after, extra_latex_before) {
new_row <- latex_row_cells(target_row)
if (bold) {
new_row <- lapply(new_row, function(x) {
Expand Down Expand Up @@ -309,24 +311,30 @@ latex_new_row_builder <- function(target_row, table_info,
# new_row <- paste0("\\\\rowcolor", latex_color(background), " ", new_row)
# }

if (!hline_after & is.null(extra_latex_after)) {
return(new_row)
} else {
latex_after <- "\\\\\\\\"
if (hline_after) {
if (table_info$booktabs) {
latex_after <- paste0(latex_after, "\n\\\\midrule")
} else {
latex_after <- paste0(latex_after, "\n\\\\hline")
}
}
if (!is.null(extra_latex_after)) {
latex_after <- paste0(latex_after, "\n",
regex_escape(extra_latex_after,
double_backslash = TRUE))
latex_after <- "\\\\\\\\"
latex_before <- ""

if (hline_after) {
if (table_info$booktabs) {
latex_after <- paste0(latex_after, "\n\\\\midrule")
} else {
latex_after <- paste0(latex_after, "\n\\\\hline")
}
return(c(new_row, latex_after))
}

if (!is.null(extra_latex_after)) {
latex_after <- paste0(latex_after, "\n",
regex_escape(extra_latex_after,
double_backslash = TRUE))
}

if (!is.null(extra_latex_before)) {
latex_before <- paste0(latex_before,
regex_escape(extra_latex_before,
double_backslash = TRUE), '\n')
}

return(c(latex_before, new_row, latex_after))
}


2 changes: 1 addition & 1 deletion man/header_separate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/row_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions man/spec_barplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.