forked from r4ds/bookclub-rpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03-system-setup.Rmd
221 lines (146 loc) · 7.37 KB
/
03-system-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
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
# System setup
**Learning objectives:**
- How to check which version of R and RStudio you are using
- Discover `devtools`
- Learn about the `{usethis}` package
- Understand the distict difference between useRs and developeRs
## Prepare your system
To start the preparation of development environment, lets get our bearings.
```{r, How to check your R version, eval=TRUE}
R.Version()
```
```{r, Another way to check your R version, eval=TRUE}
sessionInfo()
```
Ok, that was fun, but the version check isn't in the book! We need to follow the author, right?
Let's load some packages to prepare authoring some packages!
```{r, Prepare your system, eval=FALSE}
install.packages(c("devtools", "roxygen2", "testthat", "knitr"))
```
> NOTE: For some reason, this script caused an infinite loop of restart R, attempt to install, request to restart R, attempt to install...infinity. If this should happen, select *No*.
The author recommends increasing to the *Preview* version of RStudio Integrated Development Environment (IDE). We are considering outselves developers, right?
- Usually this isn't needed or required for common users (we're not common)
- It puts you in a position to be subject to bugs (not as many as the daily builds though)
- [Preview version](https://www.rstudio.com/products/rstudio/download/preview/)
- [Released version]( https://www.rstudio.com/products/rstudio/download/)
## devtools, usethis, and you
At some point in your development career...you will find you need to reorder to progress further. This is exactly what happened to the `{devtools}` package. In 2018, it was reordered and split into seven sub-packages:
- `{remotes}`
- `{pkgbuild}`
- `{pkgload}`
- `{rcmdcheck}`
- `{revdepcheck}`
- `{sessioninfo}`
- `{usethis}`
What is cool here, we already used one of these packages!!!
You can think of devtools as a wrapper providing the ability to:
- set user-friendly defaults
- introduce helpful interactive behaviour
- combine functionality from multiple sub-packages
There is a difference in useRs and developeRs. They are:
- useRs should attach devtools and think of it as the provider of your favorite functions for package development
- developeRs should **NOT** depend on devtools, but should instead access functions via the package that is their primary home
- devtools should rarely appear in the role of `foo` in a qualified call of the form `foo::fcn()`. Instead, `foo` should be the package where `fcn()` is defined.
- An exception to this is that we continue to feature `devtools::install_github()` as the way to install the development version of a package in its README
- If required, ensure you report bugs to each sub-package
Example of how to simulate installing and loading a package (interactive development)
```{r, Interactive pacakge load, eval=TRUE}
library(devtools)
load_all()
```
If used inside an R package, this is the preferred call:
```{r, Inside an R Package, eval=TRUE}
pkgload::load_all()
```
### Personal startup configuration
Attach devtools with the following script:
```{r, Installing DevTools, eval=TRUE}
library(devtools)
```
Doing this everytime you restart your session gets old...quick! Lets be more efficient with our keystrokes.
Let's edit our `.Rprofile` file. If it does not exist on your computer, you can run `use_devtools()` to create it.
The output of my command looks like this:
```{r, Example .Rprofile entry, eval=FALSE}
use_devtools()
• Include this code in '.Rprofile' to make devtools available in all interactive sessions.
if (interactive()) {
suppressMessages(require(devtools))
}
[Copied to clipboard]
• Modify '/Users/rmetcalf/.Rprofile'
• Restart R for changes to take effect
```
Caution, Warning, HUGE RED FLAG!!!! You are not a Super-person yet!
In general, it’s a bad idea to attach packages in .Rprofile, as it invites you to create R scripts that don’t reflect all of their dependencies via explicit calls to library(foo). But devtools is a workflow package that smooths the process of package development and is, therefore, unlikely to get baked into any analysis scripts.
> Note how we still take care to only attach in interactive sessions.
I may be too harsh. The following is a good example when `usethis` helps and can be added to your .Rprofile.
```{r, Example R Code, eval=FALSE}
options(
usethis.full_name = "Jane Doe",
usethis.description = list(
`Authors@R` = 'person("Jane", "Doe", email = "[email protected]", role = c("aut", "cre")),
comment = c(ORCID = "YOUR-ORCID-ID"))',
License = "MIT + file LICENSE",
Version = "0.0.0.9000"
),
usethis.protocol = "ssh"
)
```
For history purposes (or at some point it may change....)
```{r, Install DevTools and UseThis, eval=FALSE}
devtools::install_github("r-lib/devtools")
devtools::install_github("r-lib/usethis")
```
## R build toolchain
Any good developer must have a good compiler. The following three sections will expand on how this may be accomplished via the three main operating systems.
>NOTE: At this point, these may not be required. The compiler options will becomre important when a source code contains C or C++ code.
### Windows
On Windows the collection of tools needed for building packages from source is called [Rtools](https://cran.r-project.org/bin/windows/Rtools/).
Rtools is **NOT** an R package and therefore cannot be installed using `install.packages('Rtools')`
During the Rtools installation you may see a window asking you to *Select Additional Tasks*.
- **DO NOT** select the box for ***Edit the system PATH***.
- **DO** select the box for ***Save version information to registry***.
### macOS
If development is on a Mac, you will require Xcode.
In shell/terminal run the following code:
```{bash, eval=FALSE}
xcode-select --install
```
>NOTE: Xcode is large....like, ~90GBs large (an estimate with all simulators)! There are options to reduce the size and can be found [here](https://apple.stackexchange.com/questions/287307/reduce-size-of-the-xcode-application#:~:text=Go%20to%20~%2FLibrary%2FDeveloper,%2FXcode%2FiOS%20DeviceSupport%2F%20.).
Alternatively, you can also download Xcode from the [Mac App Store](https://itunes.apple.com/ca/app/xcode/id497799835?mt=12).
### Linux
Linux install is the simplest (dependent on your distro of choice and package manager).
Ensure you include the following:
- R
- R development tools
For example, on Ubuntu (and Debian):
```{bash, eval=FALSE}
sudo apt-get update & upgrade
sudo apt-get install r-base-dev package
```
Other Linux distributions may have alternative commands.
### Verify system prep
To validate everything is installed or up to date, run the following:
```{r, Validation and Update if required, eval=FALSE}
devtools::dev_sitrep()
```
Update any packages based on recommendations.
## Meeting Videos
### Cohort 1
`r knitr::include_url("https://www.youtube.com/embed/3r-EPc9XqxE")`
### Cohort 2
`r knitr::include_url("https://www.youtube.com/embed/vfrAbmqjR1c")`
### Cohort 3
`r knitr::include_url("https://www.youtube.com/embed/SEJmtdIWC-g")`
<details>
<summary> Meeting chat log </summary>
```
00:10:39 Ryan Metcalf: 20C = 68F. Awesome Temp!
00:36:24 Brendan Lam: 12.3.1 is my version
00:37:54 Larissa Shaughnessy: This just made me realize I need to update from 12.2 so thanks Brendan!
00:48:53 collinberke: Package for styling your console messages: https://cli.r-lib.org/
01:05:50 Arun Chavan: Mac
01:05:54 Isabella Velásquez: Also Mac
01:05:59 Larissa Shaughnessy: Mac
```
</details>