/
export-docs.R
91 lines (89 loc) · 2.75 KB
/
export-docs.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#' Export BioCompute Object as PDF
#'
#' @param x BioCompute Object JSON string from \code{\link{convert_json}}
#' @param file PDF output file path
#' @param wrap Should the long lines be wrapped?
#' @param linewidth Maximum linewidth when \code{wrap} is \code{TRUE}.
#' @param ... Additional parameters for \code{\link[rmarkdown]{render}}.
#'
#' @return Path to the output file
#'
#' @importFrom rmarkdown render
#'
#' @export export_pdf
#'
#' @examples
#' \dontrun{
#' file_pdf <- tempfile(fileext = ".pdf")
#' generate_example("HCV1a") %>%
#' convert_json() %>%
#' export_pdf(file_pdf)
#' }
export_pdf <- function(x, file, wrap = FALSE, linewidth = 80, ...) {
template <- normalizePath(system.file("templates/export.Rmd", package = "biocompute"))
rmarkdown::render(
input = template,
output_format = "pdf_document",
output_file = file,
clean = TRUE,
params = list(x = x, wrap = wrap, linewidth = linewidth), ...
)
}
#' Export BioCompute Object as HTML
#'
#' @param x BioCompute Object JSON string from \code{\link{convert_json}}
#' @param file HTML output file path
#' @param wrap Should the long lines be wrapped?
#' @param linewidth Maximum linewidth when \code{wrap} is \code{TRUE}.
#' @param ... Additional parameters for \code{\link[rmarkdown]{render}}.
#'
#' @return Path to the output file
#'
#' @export export_html
#'
#' @examples
#' \dontrun{
#' file_html <- tempfile(fileext = ".html")
#' generate_example("HCV1a") %>%
#' convert_json() %>%
#' export_html(file_html)
#' }
export_html <- function(x, file, wrap = FALSE, linewidth = 80, ...) {
template <- normalizePath(system.file("templates/export.Rmd", package = "biocompute"))
rmarkdown::render(
input = template,
output_format = "html_document",
output_file = file,
clean = TRUE,
params = list(x = x, wrap = wrap, linewidth = linewidth), ...
)
}
#' Export BioCompute Object as Word document
#'
#' @param x BioCompute Object JSON string from \code{\link{convert_json}}
#' @param file Word (docx) output file path
#' @param wrap Should the long lines be wrapped?
#' @param linewidth Maximum linewidth when \code{wrap} is \code{TRUE}.
#' @param ... Additional parameters for \code{\link[rmarkdown]{render}}.
#'
#' @return Path to the output file
#'
#' @export export_word
#'
#' @examples
#' \dontrun{
#' file_docx <- tempfile(fileext = ".docx")
#' generate_example("HCV1a") %>%
#' convert_json() %>%
#' export_word(file_docx)
#' }
export_word <- function(x, file, wrap = FALSE, linewidth = 80, ...) {
template <- normalizePath(system.file("templates/export.Rmd", package = "biocompute"))
rmarkdown::render(
input = template,
output_format = "word_document",
output_file = file,
clean = TRUE,
params = list(x = x, wrap = wrap, linewidth = linewidth), ...
)
}