-
Notifications
You must be signed in to change notification settings - Fork 8
/
new_package.Rd
328 lines (259 loc) · 13.6 KB
/
new_package.Rd
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/new_package.R
\name{new_package}
\alias{new_package}
\title{Create an R package structure}
\usage{
new_package(
license = "GPL (>= 2)",
status = NULL,
lifecycle = NULL,
contributing = TRUE,
code_of_conduct = TRUE,
vignette = TRUE,
test = TRUE,
create_repo = TRUE,
private = FALSE,
gh_check = TRUE,
codecov = TRUE,
website = TRUE,
gh_render = TRUE,
gh_citation = TRUE,
given = NULL,
family = NULL,
email = NULL,
orcid = NULL,
organisation = NULL,
overwrite = FALSE,
quiet = FALSE
)
}
\arguments{
\item{license}{A character vector of length 1. The license to be used for
this package. Run \code{\link[=get_licenses]{get_licenses()}} to choose an appropriate one.
Default is \code{license = 'GPL (>= 2)'}
The license can be changed later by calling \code{\link[=add_license]{add_license()}} (and
\code{\link[=add_license_badge]{add_license_badge()}} or \code{\link[=refresh]{refresh()}} to update the corresponding badge in
the README).}
\item{status}{A character vector of length 1. The status of the project
according to the standard defined by the \url{https://www.repostatus.org}
project. One among \code{'concept'}, \code{'wip'}, \code{'suspended'},
\code{'abandoned'}, \code{'active'}, \code{'inactive'}, or \code{'unsupported'}.
See \code{\link[=add_repostatus_badge]{add_repostatus_badge()}} for further information.
This argument is used to add a badge to the \code{README.Rmd} to help visitors
to better understand your project. If you don't want this badge use
\code{status = NULL} (default).
This status can be added/changed later by using \code{\link[=add_repostatus_badge]{add_repostatus_badge()}}.}
\item{lifecycle}{A character vector of length 1. The life cycle stage of the
project according to the standard defined at
\url{https://lifecycle.r-lib.org/articles/stages.html}. One among
\code{'experimental'}, \code{'stable'}, \code{'deprecated'}, or \code{'superseded'}.
See \code{\link[=add_lifecycle_badge]{add_lifecycle_badge()}} for further information.
This argument is used to add a badge to the \code{README.Rmd} to help visitors
to better understand your project. If you don't want this badge use
\code{lifecycle = NULL} (default).
This stage can be added/changed later by using \code{\link[=add_lifecycle_badge]{add_lifecycle_badge()}}.}
\item{contributing}{A logical value. If \code{TRUE} (default) adds a
\code{CONTRIBUTING.md} file and \code{ISSUE_TEMPLATES}. See \code{\link[=add_contributing]{add_contributing()}} for
further information.}
\item{code_of_conduct}{A logical value. If \code{TRUE} (default) adds a
\code{CODE_OF_CONDUCT.md} file. See \code{\link[=add_code_of_conduct]{add_code_of_conduct()}} for further
information.}
\item{vignette}{A logical value. If \code{TRUE} (default) creates a vignette in
\verb{vignettes/}. Packages \href{https://yihui.org/knitr/}{\code{knitr}} and
\href{https://rmarkdown.rstudio.com/}{\code{rmarkdown}} are also added to the
\code{Suggests} field in the \code{DESCRIPTION} file.}
\item{test}{A logical value. If \code{TRUE} (default) initializes units tests by
running \code{\link[usethis:use_testthat]{usethis::use_testthat()}}. Package
\href{https://testthat.r-lib.org}{\code{testthat}} is also added to the \code{Suggests}
field in the \code{DESCRIPTION} file.}
\item{create_repo}{A logical value. If \code{TRUE} (default) creates a repository
(public if \code{private = FALSE} or private if \code{private = TRUE}) on GitHub.
See below the section \strong{Creating a GitHub repo}.}
\item{private}{A logical value. If \code{TRUE} creates a private repository on
user GitHub account (or organisation). Default is \code{private = FALSE}.}
\item{gh_check}{A logical value. If \code{TRUE} (default) configures GitHub
Actions to automatically check and test the package after each push. This
will run \verb{R CMD check} on the three major operating systems (Ubuntu, macOS,
and Windows) on the latest release of R. See \code{\link[=add_github_actions_check]{add_github_actions_check()}}
for further information.
If \code{create_repo = FALSE} this argument is ignored.}
\item{codecov}{A logical value. If \code{TRUE} (default) configures GitHub
Actions to automatically report the code coverage of units tests after
each push. See \code{\link[=add_github_actions_codecov]{add_github_actions_codecov()}} for further information.
If \code{create_repo = FALSE} this argument is ignored.}
\item{website}{A logical value. If \code{TRUE} (default) configures GitHub
Actions to automatically build and deploy the package website
(using \href{https://pkgdown.r-lib.org/index.html}{\code{pkgdown}})
after each push. A \strong{gh-pages} branch will be created using
\code{\link[usethis:use_github_pages]{usethis::use_github_pages()}} and the GitHub repository will be
automatically configured to deploy website.
If \code{create_repo = FALSE} this argument is ignored.}
\item{gh_render}{A logical value. If \code{TRUE} (default) configures GitHub
Actions to automatically knit the \code{README.Rmd} after each push.
See \code{\link[=add_github_actions_render]{add_github_actions_render()}} for further information.
If \code{create_repo = FALSE} this argument is ignored.}
\item{gh_citation}{A logical value. If \code{TRUE} (default) configures GitHub
Actions to automatically update the \code{CITATION.cff} file.
See \code{\link[=add_github_actions_citation]{add_github_actions_citation()}} for further information.
If \code{create_repo = FALSE} this argument is ignored.}
\item{given}{A character vector of length 1. The given name of the
maintainer of the package. If \code{NULL} (default) the function will try to
get this value by reading the \code{.Rprofile} file.
For further information see \code{\link[=set_credentials]{set_credentials()}} and below the section
\strong{Managing credentials}.}
\item{family}{A character vector of length 1. The family name of the
maintainer of the package. If \code{NULL} (default) the function will try to
get this value by reading the \code{.Rprofile} file.
For further information see \code{\link[=set_credentials]{set_credentials()}} and below the section
\strong{Managing credentials}.}
\item{email}{A character vector of length 1. The email address of the
maintainer of the package. If \code{NULL} (default) the function will try to
get this value by reading the \code{.Rprofile} file.
For further information see \code{\link[=set_credentials]{set_credentials()}} and below the section
\strong{Managing credentials}.}
\item{orcid}{A character vector of length 1. The ORCID of the maintainer of
the package. If \code{NULL} (default) the function will try to get this value
by reading the \code{.Rprofile} file.
For further information see \code{\link[=set_credentials]{set_credentials()}} and below the section
\strong{Managing credentials}.}
\item{organisation}{A character vector of length 1. The GitHub organisation
to host the repository. If defined it will overwrite the GitHub pseudo.
Default is \code{organisation = NULL} (the GitHub pseudo will be used).}
\item{overwrite}{A logical value. If \code{TRUE} files written from templates and
modified by user are erased. Default is \code{overwrite = FALSE}.
\strong{Be careful while using this argument}.}
\item{quiet}{A logical value. If \code{TRUE} messages are deleted. Default is
\code{FALSE}.}
}
\value{
No return value.
}
\description{
This function creates a new R package structure according to the current
best practices.
Essential features of an R package are created (\code{DESCRIPTION} and
\code{NAMESPACE} files, and \verb{R/} and \verb{man/} folders). The project is also
\strong{versioned with git} and a generic R \code{.gitignore} is added.
\strong{IMPORTANT -} Before using this function user needs to create a new folder
(or a new project if using RStudio) and run this function inside this folder
(by using \code{\link[=setwd]{setwd()}} or by opening the \code{Rproj} in a new RStudio session).
\strong{The name of the package will be the same as the name of this folder}.
Some rules must be respected:
\url{https://r-pkgs.org/workflow101.html#name-your-package}.
Some fields of the \code{DESCRIPTION} file (maintainer information, package name,
license, URLs, and \code{roxygen2} version) are automatically filled but
others (like title and description) need to be edited manually.
Additional features are also created: a \code{CITATION} file, a \code{README.Rmd}, and
\verb{tests/} and \verb{vignettes/} folders (optional). See the vignette
\href{https://frbcesab.github.io/rcompendium/articles/rcompendium.html}{Get started}
for a complete overview of the full structure.
A GitHub repository can also be created (default) following the
"GitHub last" workflow
(\url{https://happygitwithr.com/existing-github-last.html}).
Configuration files for GitHub Actions to automatically 1) check the
package, 2) test and report code coverage, and 3) deploy the website using
\href{https://pkgdown.r-lib.org/index.html}{\code{pkgdown}}
will be added in the \verb{.github/} folder. See below the section
\strong{Creating a GitHub repo}.
}
\section{Recommended workflow}{
The purpose of the package \code{rcompendium} is to make easier the creation of R
package/research compendium so that user can focus on the code/analysis
instead of wasting time organizing files.
The recommended workflow is:
\enumerate{
\item Create an empty RStudio project;
\item Store your credentials with \code{\link[=set_credentials]{set_credentials()}} (if not already done);
\item Run \code{\link[=new_package]{new_package()}} to create a new package structure (and the GitHub
repository);
\item Edit some metadata in \code{DESCRIPTION}, \code{CITATION}, and \code{README.Rmd};
\item Implement, document & test functions (the fun part);
\item Update the project (update \code{.Rd} files, \code{NAMESPACE}, external
dependencies in \code{DESCRIPTION}, re-knit \code{README.Rmd}, and check package
integrity) with \code{\link[=refresh]{refresh()}};
\item Repeat steps 5 and 6 while developing the package.
}
}
\section{Managing credentials}{
You can use the arguments \code{given}, \code{family}, \code{email}, and \code{orcid}
directly with the function \code{\link[=new_package]{new_package()}} (and others). But if you create
a lot a projects (packages and/or compendiums) it can be frustrating in the
long run.
An alternative is to use \strong{ONCE AND FOR ALL} the function
\code{\link[=set_credentials]{set_credentials()}} to permanently store this information in the
\code{.Rprofile} file. If these arguments are set to \code{NULL} (default) each
function of the package \code{rcompendium} will search in this \code{.Rprofile} file.
It will save your time (it's the purpose of this package).
Even if you have stored your information in the \code{.Rprofile} file you will
always be able to modify them on-the-fly (i.e. by using arguments of the
\code{\link[=new_package]{new_package()}}) or permanently by re-running \code{\link[=set_credentials]{set_credentials()}}.
}
\section{Configuring git}{
First run \code{\link[gh:gh_whoami]{gh::gh_whoami()}} to see if your git is correctly configured. If
so you should see something like:
\if{html}{\out{<div class="sourceCode">}}\preformatted{\{
"name": "John Doe",
"login": "jdoe",
"html_url": "https://github.com/jdoe",
...
\}
}\if{html}{\out{</div>}}
Otherwise you might need to run:
\if{html}{\out{<div class="sourceCode">}}\preformatted{gert::git_config_global_set(name = "user.name",
value = "John Doe")
gert::git_config_global_set(name = "user.email",
value = "john.doe@domain.com")
gert::git_config_global_set(name = "github.user",
value = "jdoe")
}\if{html}{\out{</div>}}
See \code{\link[gert:git_config]{gert::git_config_global_set()}} for further information.
}
\section{Creating a GitHub repo}{
To create the GitHub repository directly from R, the package \code{rcompendium}
uses the function \code{\link[usethis:use_github]{usethis::use_github()}}, an client to the GitHub REST API.
The interaction with this API required an authentication method: a
\strong{GITHUB PAT} (Personal Access Token).
If you don't have a \strong{GITHUB PAT} locally stored, you must:
\enumerate{
\item Obtain a new one from your GitHub account. \strong{Make sure to select
at least the first two scopes (private repository and workflow)}
\item Store it in the \verb{~/.Renviron} file by using \code{\link[usethis:edit]{usethis::edit_r_environ()}}
and adding the following line: \code{GITHUB_PAT='ghp_99z9...z9'}
}
Run \code{\link[usethis:github-token]{usethis::gh_token_help()}} for more information about getting and
configuring a \strong{GITHUB PAT}.
If everything is well configured you should see something like this after
calling \code{\link[gh:gh_whoami]{gh::gh_whoami()}}:
\if{html}{\out{<div class="sourceCode">}}\preformatted{\{
"name": "John Doe",
"login": "jdoe",
"html_url": "https://github.com/jdoe",
"scopes": "delete_repo, repo, workflow",
"token": "ghp_99z9...z9"
\}
}\if{html}{\out{</div>}}
And you will be able to create a GitHub repository directly from R!
}
\examples{
\dontrun{
library(rcompendium)
## Define **ONCE FOR ALL** your credentials ----
set_credentials(given = "John", family = "Doe",
email = "john.doe@domain.com",
orcid = "9999-9999-9999-9999", protocol = "ssh")
## Create an R package ----
new_package()
## Start developing functions ----
## ...
## Update package (documentation, dependencies, README, check) ----
refresh()
}
}
\seealso{
Other setup functions:
\code{\link{new_compendium}()},
\code{\link{refresh}()},
\code{\link{set_credentials}()}
}
\concept{setup functions}