-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_setup.Rmd
189 lines (123 loc) · 5.43 KB
/
package_setup.Rmd
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
---
title: "Setup of `isotopeconverter`"
author: "Jason Mercer"
date: "May 28, 2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
eval = FALSE)
```
__To do:__
* __Check on the travis integration once I've sent a push request to my repo.__
* __Check on appveyor integration.__
* __Check code coverage.__
This document includes the commands (and musings) used to setup the `isotopeconverter` package, both for my records and for others interested in the workflow. I'm largely following the guidelines laid out by Emil Hvitfeldt's blog post, [usethis workflow for package development](https://www.hvitfeldt.me/blog/usethis-workflow-for-package-development/)
## Git and GitHub setup
I did this a bit back-asswards, but my workflow was:
1. Setup repo on GitHub.
2. Clone repo to local machine.
If I could do it over again, I probably would have followed Emil's exact workflow, but I'd already started.
## Package generation
Load the packages I'm going to use.
```{r}
#Explicitly used libraries
library(usethis)
library(devtools)
library(available)
library(covr) #Used for code coverage
#Implicitly used packages
#library(roxygen2)
#library(spelling)
```
Check that the proposed package name is available and not associated with some weird sex act (the function checks if there is an Urban Dictionary entry).
```{r}
available::available("isotopeconverter")
```
Create the package!
```{r}
usethis::create_package(path = getwd())
```
First time I did this I entered "~" as the argument to `path` and it made me project in my home directory, rather than my working directory. So, be explicit.
That was kind of a weird step, because it wanted me overwrite the Rproject I was already working in. I just told the dialogue box not not to overwrite. Everything seems okay.
Once I made the package I updated the `DESCRIPTION` file with my information. Also, I did not have access to the "Build" tab (next to Environment, History, and Connections) until re-starting RStudio.
### Other package odds and ends
License
```{r}
usethis::use_gpl3_license(name = "Jason Mercer")
```
Adding a readme (since I didn't generate one on GitHub).
```{r}
usethis::use_readme_md()
```
## Setup continuous integration
### travis
As I understand it, Travis is used to check continuous integration on Unix-based systems.
```{r}
usethis::use_travis()
```
I'd not actually registered with travis-ci yet, so when I ran this code I went to a page that didn't exist. However, by navigating to https://travis-ci.org I was automatically taken to a registration page that knew I was trying to link my GitHub account to travis. Once I entered my entered my GitHub account, everything seemed to sync.
I've updated my `.travis.yml` file to contain the following information after watching the [continuous integration video](https://www.youtube.com/watch?v=As5SM7-F02w&list=PLk3B5c8iCV-T4LM0mwEyWIunIunLyEjqM&index=3) by John Muschelli:
```
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
language: R
cache: packages
os:
- linux
- osx
r:
- oldrel
- release
- devel
r_packages:
- covr
after_success:
- Rscript -e 'library(covr); codecov()'
```
Okay, it looks like because I've setup unit tests, but haven't actually populated the `tests/testthat.R` file with any tests. So, for now, I've commented out the `test_check` line.
```{r}
library(testthat)
library(isotopeconverter)
#test_check("isotopeconverter")
```
### appveyor
Appveyor is Travis for Windows. So, by having both Travis and Appveyor, I have continuous integration across platforms.
```{r}
usethis::use_appveyor()
```
Similar experience to Travis -- didn't have an account and so I registered using my GitHub account.
Comment: Seems GitLab may have its own continuous integration tools.
## Unit testing
### codecov
Provides some indication of how well unit tests cover the code being generated. I'm going to use it to try to shame myself into learning how to better use unit tests via the `testthat` package.
```{r}
usethis::use_coverage(type = "codecov")
```
This required me to install the package `covr`.
The codecov dashboard provides a token for use with my package, but I'm not entirely sure what to do with it. Also, the `usethis` function prompted me to add the following code to my `.travis.yml` file:
```
after_success:
- Rscript -e 'library(covr); codecov()'
```
The example R package from [codecov](https://github.com/codecov/example-r) has a slightly different ammendment:
```
r_packages:
- covr
after_success:
- Rscript -e 'library(covr); codecov()'
```
### Setup `testthat`
```{r}
usethis::use_testthat()
```
Once I'm ready, I should use `usethis::use_test()` to setup unit tests.
### More package odds and ends
```{r}
usethis::use_spell_check()
```
To actually spell-check: `devtools::check()`.
## Loose ends I've figured out
`usethis::use_build_ignore` is useful for adding files and folders to the `.Rbuildignore` file. I figured this out when using `devtools::check`, which was returning a "Note" that I had a non-standard file in my package. It was
## More stuff that could be done.
Here is a comprehensive list of other functions that should be perused for other things I'd like to add to the package: https://usethis.r-lib.org/reference/index.html
And... I think that's