-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.qmd
184 lines (141 loc) · 6.67 KB
/
setup.qmd
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
---
title: "System Setup"
---
## Software Tools
Development of Workbench components requires the same toolchain for working on
lessons:
- R
- pandoc
- Git
It is recommended to have the latest versions of R and pandoc available. You
need at least git 2.28 for security purposes.
```{r}
#| echo: false
#| message: true
cat("R version\n---\n")
writeLines(system2(c("R", "--version"), stdout = TRUE))
cat("\npandoc version\n---\n")
writeLines(system2(c("pandoc", "--version"), stdout = TRUE))
cat("\ngit version\n---\n")
writeLines(system2(c("git", "--version"), stdout = TRUE))
```
## R Packages
Once you have these installed, make sure to install ALL of the dependencies for
the workbench:
```{.r}
install.packages(c("sandpaper", "pegboard", "varnish", "tinkr"),
dependencies = TRUE,
repos = c(getOption("repos"), "https://carpentries.r-universe.dev"))
```
:::{.callout-tip}
### Working on Linux?
If you are on Linux, you will run into a couple of fun aspects that you may
already be familiar with, especially if you have ever tried to install
bioinformatic software:
1. having to also install some extra C libraries (which are akin to R packages,
but for C), such as the `xslt` library.
2. having to build all packages from source
You can find detailed instructions in [The Sandpaper Setup
Guide](https://carpentries.github.io/sandpaper-docs/#infrastructure-r-packages-2),
but the relevant commands are below.
### System Dependencies {-}
Here is the gist **for Ubuntu Users to get system dependencies set up.** Use
[The Carpentries R-Universe](https://carpentries.r-universe.dev) API to get all
of the system dependencies. Here's how to do that via CURL:
```bash
curl https://carpentries.r-universe.dev/stats/sysdeps 2> /dev/null | jq -r '.headers[0] | select(. != null)'
```
This list can be sent to `apt-get install` to install everything:
```bash
sudo apt-get install -y \
$(curl https://carpentries.r-universe.dev/stats/sysdeps 2> /dev/null | jq -r '.headers[0] | select(. != null)') 2> /dev/null \
|| echo "Not on Ubuntu"
```
### Binary Packages {-}
To get binary packages for your system, I will admit that it's _slightly
confusing_ because they bury the [instructions for registering your system to
use binaries in the _admin_
pages](https://packagemanager.posit.co/__docs__/admin/serving-binaries/#binaries-r-configuration-linux)
and even then, it's kinda long. The gist is that you need to do two things:
1. set your HTTPUserAgent header to state your R version and platform
2. add the packagemanager CRAN-like repository to R's options:
Here's a script that you can copy and paste into `~/.Rprofile` which will be
run every time you start R
```r
local({
# Set the default HTTP user agent to get pre-built binary packages
RV <- getRversion()
OS <- paste(RV, R.version["platform"], R.version["arch"], R.version["os"])
codename <- sub("Codename.\t", "", system2("lsb_release", "-c", stdout = TRUE))
options(HTTPUserAgent = sprintf("R/%s R (%s)", RV, OS))
# register the repositories for The Carpentries and CRAN
options(repos = c(
carpentries = "https://carpentries.r-universe.dev/",
CRAN = paste0("https://packagemanager.posit.co/all/__linux__/", codename, "/latest")
))
})
```
When you have this set up, you can then install the workbench packages:
```r
# Install The Workbench and dependencies
install.packages(c("sandpaper", "varnish", "pegboard", "tinkr"), dep = TRUE)
```
:::
The {sandpaper} package comes with the [{usethis}](https://usethis.r-lib.org)
package embedded (though this may change in the future). In addition, you will
need the [{devtools}](https://devtools.r-lib.org) for development.
I would also _highly_ recommend the [{pandoc}](https://cderv.github.io/pandoc/)
package for managing pandoc versions (NOTE: this requires you to have a
personal access token set up).
```{.r}
install.packages("devtools")
install.packages("pandoc")
```
Once you have devtools, be sure to run `devtools::dev_sitrep()` and `usethis::git_sitrep()` to make sure you have the tools to build The Workbench:
``` r
devtools::dev_sitrep()
#> ── R ───────────────────────────────────────────────────────────────────────────
#> • version: 4.3.0
#> • path: '/usr/lib/R/'
#> ── devtools ────────────────────────────────────────────────────────────────────
#> • version: 2.4.5
#> ── dev package ─────────────────────────────────────────────────────────────────
#> • package: <unset>
#> • path: <unset>
#> ✔ All checks passed
usethis::git_sitrep()
#> Git config (global)
#> • Name: 'Zhian N. Kamvar'
#> • Email: '[email protected]'
#> • Global (user-level) gitignore file: <unset>
#> • Vaccinated: FALSE
#> ℹ See `?git_vaccinate` to learn more
#> ℹ Defaulting to 'https' Git protocol
#> • Default Git protocol: 'https'
#> • Default initial branch name: 'main'
#> GitHub
#> • Default GitHub host: 'https://github.com'
#> • Personal access token for 'https://github.com': '<discovered>'
#> • GitHub user: 'zkamvar'
#> • Token scopes: 'gist, repo, user, workflow'
#> • Email(s): '[email protected] (primary)', ...
#> Git repo for current project
#> ℹ No active usethis project
```
<sup>Created on 2023-05-30 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup>
## Development Workflow
This development workflow is known as Test Driven Development in which a test is
written _before_ things work. This way, we can confirm that a bug is fixed once
it passes the tests and we have confidence that it will not fail again.
1. open RStudio and switch to the project for the package you are working on
2. checkout a new branch for your feature/bug
3. **load package** via `devtools::load_all()` or <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>L</kbd> (
use <kbd>cmd</kbd> on macOS) to load the package NAMESPACE
4. (if needed) **document** (either via `devtools::document()` or <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>D</kbd>)
5. **run tests** (either via `devtools::test()` or
<kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>T</kbd> to run the entire test suite
OR to test a single file, use the "run tests" button in a test file or run
`testthat::test_local(filter = '[FILE SLUG]')`
6. **modify tests** for new functionality/bug fix
7. **add functionality/bug fix** and move to 3 unless you are ready to push
8. run check with `devtools::check()` or <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>E</kbd>