-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrcompendium.Rmd
More file actions
268 lines (148 loc) · 6.72 KB
/
rcompendium.Rmd
File metadata and controls
268 lines (148 loc) · 6.72 KB
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
---
title: "Get started with rcompendium"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Get started with rcompendium}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
```
`rcompendium` makes easier the creation of R packages or research compendia
(i.e. a predefined files/folders structure) so that users can focus on the
code/analysis instead of wasting time organizing files. A full ready-to-work
structure is set up with some additional features: version control, remote
repository creation, CI/CD configuration (check package integrity under
several OS, test code with `testthat`, and build and deploy website using
`pkgdown`).
<br/>
## Prerequisites
Before using the package `rcompendium` you must follow these three steps.
<br/>
### GIT configuration
First ensure that **GIT** is correctly installed on your machine and linked to
RStudio. Read the Chapter 6 of
[Happy Git and GitHub for the useR](https://happygitwithr.com/install-git.html).
You also need to store your GIT credentials locally (i.e. for the project) or
globally (recommended). Run `gh::gh_whoami()` to see if your git and associated
credentials are correctly configured. You should see something like:
```
{
"name": "John Doe",
"login": "jdoe",
"html_url": "https://github.com/jdoe",
...
}
```
Otherwise you might need to run:
```{r eval = FALSE}
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")
```
See `?gert::git_config_global_set` for further information.
<br/>
### Creating a GitHub repo
To create the GitHub repository directly from R, the package `rcompendium`
uses the function `usethis::use_github()`, a client to the GitHub REST API.
The interaction with this API required an authentication method: a
**GITHUB PAT** (Personal Access Token).
If you don't have a **GITHUB PAT** locally stored, you must:
1. visit the page [https://github.com/settings/tokens](https://github.com/settings/tokens)
and create a new token;
2. store it in the `~/.Renviron` file by using `usethis::edit_r_environ()`
and adding the following line: `GITHUB_PAT='ghp_99z9...z9'`.
Run `usethis::gh_token_help()` for more information about getting and
configuring a **GITHUB PAT**.
If everything is well configured, you should see something like this after
calling `gh::gh_whoami()`:
```
{
"name": "John Doe",
"login": "jdoe",
"html_url": "https://github.com/jdoe",
"scopes": "delete_repo, repo, workflow",
"token": "ghp_99z9...z9"
}
```
Then you will be able to create a GitHub repository directly from R!
<br />
### Managing credentials
You can use the arguments `given`, `family`, `email`, and `orcid`
directly with the functions `new_*()` and `add_*()`. But if you create
a lot a projects (packages and/or compendia) it can be frustrating in the
long run.
An alternative way is to use **ONCE AND FOR ALL** the function
`set_credentials()` to permanently store this information in the
`~/.Rprofile` file. If these arguments are set to `NULL` while calling any
function of the package, `rcompendium` will search their values in this file.
It will save your time (it's the purpose of this package).
Even if you have stored your credentials in the `~/.Rprofile` file you will
always be able to modify them on-the-fly (i.e. by using credentials arguments
in the functions `new_*()` and `add_*()`) or permanently by re-running
`set_credentials()`.
<br/>
## Usage
The recommended workflow is:
1. Store your credentials with `set_credentials()` (if not already done);
2. **IMPORTANT -** Create an new empty RStudio project;
3. Run `new_package()` to create a new package structure or `new_compendium()`
to create a new research compendium structure;
4. Edit some metadata in `DESCRIPTION`, `CITATION`, and `README.Rmd`;
5. Start working (add data, write and document R functions, etc.);
6. And do not forget to commit your changes.
<br/>
In addition to these three setup functions (`set_credentials()`, `new_package()`,
`new_compendium()`), the package `rcompendium` offers 29 other functions.
These can be grouped as:
- `add_*()`: functions to add/update/overwrite files, configuration settings,
dependencies, badges, etc.;
- `get_*()`: functions to retrieve some information (available licenses, R
version, etc.).
Visit the [Reference page](https://frbcesab.github.io/rcompendium/reference/index.html)
for further details.
<br/>
**To sum up**
```{r eval = FALSE}
## Define ONCE FOR ALL your credentials ----
rcompendium::set_credentials(given = "John", family = "Doe",
email = "john.doe@domain.com",
orcid = "9999-9999-9999-9999", protocol = "ssh")
## CREATE A NEW EMPTY RSTUDIO PROJECT ----
## Create an R package structure ----
rcompendium::new_package()
## Then...
## ... edit metadata in DESCRIPTION, CITATION, README.Rmd, etc.
## ... implement and document R functions in R/
## Update functions documentation and NAMESPACE ----
devtools::document()
## Update list of dependencies in DESCRIPTION ----
rcompendium::add_dependencies()
## Check package ----
devtools::check()
## Example: use of an add_*() function ...
## ... update 'Number of Dependencies Badge' in README.Rmd ----
rcompendium::add_dependencies_badge()
```
**N.B.** Users can also use functions from the package [`usethis`](https://usethis.r-lib.org/)
to add some missing features (e.g. `data/` and package release tools).
<br/>
## Resources
- [Developing an R package](https://frbcesab.github.io/rcompendium/articles/developing_a_package.html)
- [Working with a compendium](https://frbcesab.github.io/rcompendium/articles/working_with_a_compendium.html)
<br/>
## Contributing
You are welcome to contribute to the `rcompendium` project. Please read our
[Contribution Guidelines](https://frbcesab.github.io/rcompendium/CONTRIBUTING.html).
Please note that the `rcompendium` project is released with a
[Contributor Code of Conduct](https://frbcesab.github.io/rcompendium/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.
<br/>
## Colophon
This package is the result of intense discussions and feedback from the training
course [Data Toolbox for Reproducible Research in Computational Ecology](https://rdatatoolbox.github.io/).
`rcompendium` is largely inspired by the package
[`rrtools`](https://github.com/benmarwick/rrtools) developed by
[Ben Marwick _et al._](https://github.com/benmarwick) and tries to respect the standard
defined by the community. **Special thanks to these developers!**