blob: adf5e95634de6ba366078b3dbccf9f163fdc1933 [file] [log] [blame]
Hao Zhu248bbef2018-04-02 18:25:14 -04001#' Make linebreak in LaTeX Table cells
2#'
3#' @export
4linebreak <- function(x, align = c("l", "c", "r"), double_escape = F) {
5 if (is.numeric(x) | is.logical(x)) return(x)
6 align <- match.arg(align, c("l", "c", "r"))
7 if (double_escape) {
8 ifelse(str_detect(x, "\n"),
9 paste0("\\\\makecell[", align, "]{",
10 str_replace_all(x, "\n", "\\\\\\\\\\\\\\\\"), "}"),
11 x)
12 } else {
13 ifelse(str_detect(x, "\n"),
14 paste0("\\makecell[", align, "]{",
15 str_replace_all(x, "\n", "\\\\\\\\"), "}"),
16 x)
17 }
18}