/
zzz.R
157 lines (147 loc) · 4.95 KB
/
zzz.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Resources:
# .onAttach & zzz.R explained: https://r-pkgs.org/r.html#when-you-do-need-side-effects
.onAttach <- function(libname, pkgname) {
m <- c(sprintf("This is workflowr version %s",
utils::packageVersion("workflowr")),
"Run ?workflowr for help getting started")
packageStartupMessage(paste(m, collapse = "\n"))
check_dependencies()
}
.onLoad <- function(libname, pkgname) {
sysgit <- Sys.which("git")
wflow_pkg_opts <- list(
workflowr.autosave = TRUE,
workflowr.sysgit = if(fs::file_exists(sysgit)) sysgit else "",
workflowr.view = interactive()
)
op <- options()
toset <- !(names(wflow_pkg_opts) %in% names(op))
if(any(toset)) options(wflow_pkg_opts[toset])
invisible()
}
# Unfortunately I can't assume anything about the dependencies. They may be:
#
# * Not installed: a user can remove them after installing workflowr
# * Installed but unusable, e.g. one of their dependencies was removed
# * Installed but below the minimum required version
dependencies <- c(
callr = "3.7.0",
fs = "1.2.7",
getPass = NA,
git2r = "0.26.0",
glue = NA,
httpuv = "1.2.2",
httr = NA,
knitr = "1.29",
rmarkdown = "1.18",
rprojroot = "1.2",
rstudioapi = "0.6",
stringr = "1.3.0",
tools = NA,
utils = NA,
whisker = "0.3-2",
xfun = NA,
yaml = NA
)
check_dependencies <- function() {
for (i in seq_along(dependencies)) {
pkg_name <- names(dependencies)[i]
pkg_version <- dependencies[i]
if (length(find.package(pkg_name, quiet = TRUE, verbose = FALSE)) == 0) {
stop(sprintf("The required dependency \"%s\" is missing, please install it.",
pkg_name))
}
if (!requireNamespace(pkg_name, quietly = TRUE)) {
stop(sprintf("The required dependency \"%s\" is unable to be loaded, please re-install it.",
pkg_name))
}
if (!is.na(pkg_version)) {
installed_version <- utils::packageVersion(pkg_name)
if (installed_version < as.package_version(pkg_version)) {
stop(sprintf(
"Please update package \"%s\": version %s is installed, but %s is required",
pkg_name, installed_version, pkg_version
))
}
}
}
return(NULL)
}
#' workflowr: A workflow template for creating a research website
#'
#' The workflowr package helps you create a research website using R Markdown
#' and Git.
#'
#' @section Vignettes:
#'
#' Run \code{browseVignettes("workflowr")} to read the package vignettes
#' locally. Alternatively you can read the documentation online at
#' \url{https://workflowr.github.io/workflowr/}.
#'
#' @section Main workflowr functions:
#'
#' \describe{
#'
#' \item{\code{\link{wflow_start}}}{Start a workflowr project.}
#'
#' \item{\code{\link{wflow_build}}}{Build the site to view locally.}
#'
#' \item{\code{\link{wflow_publish}}}{Publish analyses to include in the
#' website.}
#'
#' \item{\code{\link{wflow_status}}}{Report status of analysis files.}
#' }
#'
#' @section Supporting workflowr functions:
#'
#' For further information on workflowr, see the help pages for these
#' functions:
#'
#' \describe{
#'
#' \item{\code{\link{wflow_html}}}{More technical details about how
#' individual R Markdown files are converted to webpages, and how the
#' rendering settings can be customized.}
#'
#' \item{\code{\link{wflow_site}}}{This help page explains how
#' project-wide rendering settings can be customized in the
#' \code{_site.yml} file.}
#' }
#'
#' @section Package options:
#'
#' The following package options affect the default behavior of the workflowr
#' functions. To permanently set any of these options, add a call to the
#' function \code{\link[base]{options}} in the file \code{.Rprofile} at the root
#' of your workflowr project. For example:
#'
#' \preformatted{
#' # Do not use Git executable
#' options(workflowr.sysgit = "")
#' }
#'
#' \describe{
#'
#' \item{workflowr.autosave}{A logical indicating whether workflowr functions
#' should automatically save files open in the RStudio editor before running.
#' The default is \code{TRUE}. This requires RStudio 1.1.287 or later. Only
#' files that have been previously saved are affected. In other words, unnamed
#' files will be ignored.}
#'
#' \item{workflowr.sysgit}{The path to the system Git executable. This is
#' occasionally used to increase the speed of Git operations performed by
#' workflowr. By default it is set to the first Git executable on the search
#' path. You can specify a path to a different Git executable. Alternatively you
#' can disable this behavior entirely by setting it to the empty string \code{""}.}
#'
#' \item{workflowr.view}{A logical indicating whether workflowr functions should
#' open webpages for viewing in the browser. The default is set to
#' \code{\link[base]{interactive}} (i.e. it is \code{TRUE} only if it is an
#' interactive R session). This option is currently used by
#' \code{\link{wflow_build}}, \code{\link{wflow_git_push}}, and
#' \code{\link{wflow_publish}}.}
#' }
#'
#' @keywords internal
#'
"_PACKAGE"