forked from r-lib/usethis
/
tidyverse.R
169 lines (136 loc) · 3.85 KB
/
tidyverse.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
158
159
160
161
162
163
164
165
166
167
168
169
#' Helpers for the tidyverse
#'
#' These helpers follow tidyverse conventions which are generally a little
#' stricter than the defaults, reflecting the need for greater rigor in
#' commonly used packages.
#'
#' @details
#'
#' * `use_tidy_ci()`: sets up travis and codecov, ensuring that the package
#' works on all versions of R starting at 3.1.
#'
#' * `use_tidy_description()`: puts fields in standard order and alphabetises
#' dependencies.
#'
#' * `use_tidy_eval()`: imports a standard set of helpers to facilitate
#' programming with the tidy eval toolkit.
#'
#' * `use_tidy_versions()`: pins all dependencies to require at least
#' the currently installed version.
#'
#' * `use_tidy_contributing()`: creates tidyverse contributing guidelines from
#' tidy_contributing template.
#'
#' * `use_tidy_issue_template()`: creates a standard tidyverse issue template.
#'
#' * `use_tidy_support()`: creates support resources document for GitHub repo
#' using SUPPORT.md.
#'
#' @name tidyverse
NULL
#' @export
#' @rdname tidyverse
#' @inheritParams use_travis
use_tidy_ci <- function(browse = interactive()) {
check_uses_github()
new <- use_template(
"tidy-travis.yml",
".travis.yml",
ignore = TRUE
)
use_template("codecov.yml", ignore = TRUE)
use_dependency("R", "Depends", ">= 3.1")
use_dependency("covr", "Suggests")
use_travis_badge()
use_codecov_badge()
if (new) {
travis_activate(browse)
}
invisible(TRUE)
}
#' @export
#' @rdname tidyverse
use_tidy_description <- function() {
base_path <- proj_get()
# Alphabetise dependencies
deps <- desc::desc_get_deps(base_path)
deps <- deps[order(deps$type, deps$package), , drop = FALSE]
desc::desc_del_deps(file = base_path)
desc::desc_set_deps(deps, file = base_path)
# Alphabetise remotes
remotes <- desc::desc_get_remotes(file = base_path)
if (length(remotes) > 0) {
desc::desc_set_remotes(sort(remotes), file = base_path)
}
# Reorder all fields
desc::desc_reorder_fields(file = base_path)
invisible(TRUE)
}
#' @export
#' @rdname tidyverse
#' @param overwrite By default (`FALSE`), only dependencies without version
#' specifications will be modified. Set to `TRUE` to modify all dependencies.
use_tidy_versions <- function(overwrite = FALSE) {
deps <- desc::desc_get_deps(proj_get())
to_change <- deps$package != "R"
if (!overwrite) {
to_change <- to_change & deps$version == "*"
}
deps$version[to_change] <- vapply(deps$package[to_change], dep_version, character(1))
desc::desc_set_deps(deps, file = proj_get())
invisible(TRUE)
}
is_installed <- function(x) {
length(find.package(x, quiet = TRUE)) > 0
}
dep_version <- function(x) {
if (is_installed(x)) paste0(">= ", utils::packageVersion(x)) else "*"
}
#' @export
#' @rdname tidyverse
use_tidy_eval <- function() {
if (!uses_roxygen()) {
stop("`use_tidy_eval()` requires that you use roxygen.", call. = FALSE)
}
use_dependency("rlang", "Imports", ">= 0.1.2")
use_template("tidy-eval.R", "R/utils-tidy-eval.R")
todo("Run document()")
}
#' @export
#' @rdname tidyverse
use_tidy_contributing <- function() {
check_uses_travis()
gh <- gh::gh_tree_remote(proj_get())
travis_url <- file.path("https://travis-ci.org", gh$username, gh$repo)
github_url <- file.path("https://github.com", gh$username, gh$repo)
use_template(
"tidy_contributing.md",
"CONTRIBUTING.md",
data = list(
package = project_name(),
github_url = github_url,
travis_url = travis_url
),
ignore = TRUE
)
}
#' @export
#' @rdname tidyverse
use_tidy_issue_template <- function() {
check_uses_github()
use_template(
"ISSUE_TEMPLATE.md",
"ISSUE_TEMPLATE.md",
ignore = TRUE
)
}
#' @export
#' @rdname tidyverse
use_tidy_support <- function() {
check_uses_github()
use_template(
"SUPPORT.md",
data = list(package = project_name()),
ignore = TRUE
)
}