-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy path_common.R
44 lines (37 loc) · 1.18 KB
/
_common.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
message = FALSE
)
options(dplyr.summarise.inform = FALSE)
rtf2pdf <- function(input) {
input <- normalizePath(input)
x <- "export LD_LIBRARY_PATH=:/usr/lib/libreoffice/program:/usr/lib/x86_64-linux-gnu/"
y <- paste0("libreoffice --invisible --headless --nologo --convert-to pdf --outdir tlf/ ", input)
z <- paste(x, y, sep = " && ")
if (Sys.getenv("GITHUB_ACTIONS") != "") system(z) else invisible(NULL)
}
# Customize data frame and tibble printing methods.
# See <https://github.com/elong0527/r4csr/issues/115> for details.
more_rows <- function(x, n) if (nrow(x) <= n) NULL else paste0("# ℹ ", nrow(x) - n, " more rows")
knit_print.data.frame <- function(x, ...) {
paste(
c(
capture.output(base::print.data.frame(head(x, 4))),
more_rows(x, 4)
),
collapse = "\n"
)
}
registerS3method(
"knit_print", "data.frame", knit_print.data.frame,
envir = asNamespace("knitr")
)
options(pillar.advice = FALSE)
knit_print.tbl_df <- function(x, ...) {
paste(capture.output(print(x, n = 4)), collapse = "\n")
}
registerS3method(
"knit_print", "tbl_df", knit_print.tbl_df,
envir = asNamespace("knitr")
)