| Hao Zhu | 248bbef | 2018-04-02 18:25:14 -0400 | [diff] [blame] | 1 | #' Make linebreak in LaTeX Table cells | 
|  | 2 | #' | 
|  | 3 | #' @export | 
|  | 4 | linebreak <- 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 | } |