-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathdeployDoc.R
80 lines (73 loc) · 2.54 KB
/
deployDoc.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
#' Deploy a single document
#'
#' @description
#' Deploys a single R Markdown, Quarto document, or other file (e.g. `.html` or
#' `.pdf`).
#'
#' When deploying an `.Rmd`, `.Qmd`, or `.html`, `deployDoc()` will attempt to
#' automatically discover dependencies using [rmarkdown::find_external_resources()],
#' and include an `.Rprofile` if present. If you find that the document is
#' missing dependencies, either specify the dependencies explicitly in the
#' document (see [rmarkdown::find_external_resources()] for details), or call
#' [deployApp()] directly and specify your own file list in `appFiles`.
#'
#' @param doc Path to the document to deploy.
#' @param ... Additional arguments to [deployApp()]. Do not supply `appDir`,
#' `appFiles`, or `appPrimaryDoc`; these three parameters are automatically
#' generated by `deployDoc` from the document.
#' @inheritParams deployApp
#' @family Deployment functions
#' @export
#' @examples
#' \dontrun{
#' deployDoc("my-report.Rmd")
#' deployDoc("static-file.html")
#' }
deployDoc <- function(doc, ..., logLevel = c("normal", "quiet", "verbose")) {
logLevel <- arg_match(logLevel)
doc <- standardizeSingleDocDeployment(doc, quiet = logLevel == "quiet")
deployApp(
appDir = doc$appDir,
appPrimaryDoc = doc$appPrimaryDoc,
appFiles = doc$appFiles,
...,
logLevel = logLevel
)
}
standardizeSingleDocDeployment <- function(path,
quiet = FALSE,
error_call = caller_env(),
error_arg = caller_arg(path)) {
check_installed(
"rmarkdown",
version = "0.5.2",
reason = "to deploy individual R Markdown documents"
)
check_file(path, error_call = error_call, error_arg = error_arg)
path <- normalizePath(path)
if (isShinyRmd(path)) {
# deploy entire directory
appFiles <- NULL
} else if (isStaticFile(path)) {
taskStart(quiet, "Discovering document dependencies...")
resources <- rmarkdown::find_external_resources(path)
taskComplete(quiet, "Document dependencies discovered")
appFiles <- c(basename(path), resources$path)
if (file.exists(file.path(dirname(path), ".Rprofile"))) {
appFiles <- c(appFiles, ".Rprofile")
}
appFiles
} else {
# deploy just the file
appFiles <- basename(path)
}
list(
appDir = normalizePath(dirname(path)),
appPrimaryDoc = basename(path),
appFiles = appFiles
)
}
isStaticFile <- function(path) {
ext <- tolower(tools::file_ext(path))
ext %in% c("rmd", "qmd", "html", "htm")
}