Skip to content

Commit b511172

Browse files
authored
Merge pull request #17 from openstatsware/consistency-checks
Edits to all chapters for consistency
2 parents 2c811b0 + 776f9ed commit b511172

File tree

6 files changed

+180
-271
lines changed

6 files changed

+180
-271
lines changed

index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Prior to the short course, participants should
5959
- Set up a (free) [GitHub.com account](https://github.com/join).
6060
- Note: There are other git platforms like [Gitlab](https://about.gitlab.com/) or [Bitbucket](https://bitbucket.org/), but we made the choice to go with GitHub.com for the course, since it is by far the most relevant git platform in the R community.
6161
- Install the latest [R](https://www.r-project.org/) and [RStudio](https://posit.co/download/rstudio-desktop/) software.
62-
- Install [Rtools](https://cran.r-project.org/bin/windows/Rtools/rtools44/rtools.html) (only on Windows and optional if you want to try out Rcpp)
62+
- Install [Rtools](https://cran.r-project.org/bin/windows/Rtools/rtools44/rtools.html) (on Windows) or the [required tools](https://mac.r-project.org/tools/) (on macOS) to compile/build packages from source code.
6363
- Install additional R packages using the [installation script](slides/download/install.R).
6464

6565
For the course, participants are required to use their own laptop to be able to participate in the exercises.

slides/01_intro.qmd

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ author: Audrey T. Yeo
1010
{{< include _disclaimer.qmd >}}
1111

1212

13-
## Welcome to GSWEP4R at the ISCB46 !
13+
## Welcome to GSWEP4R at ISCB46!
1414

1515
\
1616
\
1717

18-
_We have an open source spirit here. Please sit with someone you do not already know_
18+
_We have an open source spirit here. Please sit with someone you do not already know._
1919

2020

2121
\
@@ -33,7 +33,7 @@ Be Curious. Be Respectful. Be Kind.
3333
::: {.column width="70%"}
3434
- M Sci Biostatistics (Zurich), M Nursing (Sydney)
3535
- Currently : Founder of [Finc-Research](https://finc-research.com)
36-
- Previously : Master Thesis in Longitudinal Cluster Analysis, Biostatistician at Roche for 4 years, Paeds / Onc RN from Melbourne, Australia
36+
- Previously : Master Thesis in Longitudinal Cluster Analysis, Biostatistician at Roche for 4 years, Paeds / Onc RN from Melbourne, Australia
3737
- Lead developer of `phase1b` package, Bayesian Framework for Clinical Trials and
3838
`openstatsware` member
3939
- Enjoys developing statistical software, especially writing tests
@@ -144,7 +144,7 @@ readr::read_csv("resources/program.csv", col_types = "cc") |>
144144
## What do we mean by GSWEP4R\*?
145145

146146
::: aside
147-
\* Good Software Engineering Practice for R
147+
\* Good Software Engineering Practice for R Packages
148148
:::
149149

150150
- Applying concept of "Good XYZ Practice" to SWE with R
@@ -155,7 +155,7 @@ readr::read_csv("resources/program.csv", col_types = "cc") |>
155155

156156
## Why care about GSWEP4R?
157157

158-
- R is one of the most successfull statistical programming languages
158+
- R is one of the most successful statistical programming languages
159159
- R is a powerful yet complex *ecosystem*
160160
- Core component: R packages
161161
- Mature user & contributor community
@@ -262,13 +262,11 @@ knitr::include_graphics("resources/pkg_graph.png")
262262
- shareable
263263
- easier to document
264264

265-
# Extra motivation for today's course :
265+
# Extra motivation for today's course:
266266

267267
check out the [diversity alliance hackathon on Sep 30](https://www.linkedin.com/posts/open-source-in-pharma_diversity-alliance-hackathon-rpharma-activity-7355688433186422784-XDpd/?utm_source=share&utm_medium=member_desktop&rcm=ACoAAAm-hUYBK6599wxUyoAYIPTNW2hexCikETs) and see if you can apply today's learned skills there!
268268

269-
270-
# Question, Comments?
271-
269+
# Question, comments?
272270

273271
# License information {.smaller}
274272

slides/02_r_packages.qmd

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@ author: Alessandro Gasparini
1111

1212
# Introduction
1313

14-
## What You Know Already
14+
## What you know already
1515

16-
- Packages provide a mechanism for loading optional code, data, and
17-
documentation
16+
- Packages provide a mechanism for loading optional code, data, and documentation
1817
- A library is a directory into which packages are installed
1918
- `install.packages()` is used to install packages into the library
2019
- `library()` is used to load and attach packages from the library
21-
- "Attach" means that the package is put in your `search` list --- objects in
22-
the package can be used directly
20+
- "Attach" means that the package is put in your `search` list --- objects in the package can be used directly
2321
- Remember that **package $\neq$ library**
2422

25-
## What We Want to Talk About Now
23+
## What we want to talk about now
2624

2725
- How to write, build, test, and check your own package `r emoji::emoji("blush")`
2826
- How to do this in a methodical and sustainable way
2927
- Give tips and tricks based on practical experience
3028

31-
# Contents of a Package
29+
# Contents of a package
3230

33-
## How is a Package Structured?
31+
## How is a package structured?
3432

3533
Package source = directory with files and subdirectories
3634

@@ -54,7 +52,7 @@ Package source = directory with files and subdirectories
5452
:::
5553
:::
5654

57-
## How to Get Started Quickly
55+
## How to get started quickly
5856

5957
Once upon a time, developers would set up this structure manually `r emoji::emoji("yawning_face")`
6058

@@ -65,7 +63,7 @@ Nowadays, it's super fast with:
6563

6664
![](resources/rstudio-rpackage.png){.r-stretch}
6765

68-
## `DESCRIPTION` File
66+
## `DESCRIPTION` file
6967

7068
- *Package*: Choose the name of your package
7169
- Not unimportant!
@@ -76,7 +74,7 @@ Nowadays, it's super fast with:
7674
- *Authors@R*: Add authors and maintainer
7775
- *Description*: Like an abstract, including references
7876

79-
## `DESCRIPTION` File (cont'd)
77+
## `DESCRIPTION` file (cont'd)
8078

8179
- *License*: Important for open sourcing
8280
- Consider permissive licenses such as Apache and MIT
@@ -88,7 +86,7 @@ Nowadays, it's super fast with:
8886
- *Suggests*: Packages for documentation processing (`roxygen2`), running
8987
examples, tests (`testthat`), vignettes
9088

91-
## `R` Folder
89+
## `R` folder
9290

9391
- Only contains R code files (recommended to use `.R` suffix)
9492
- Can create a file with `usethis::use_r("filename")`
@@ -105,7 +103,7 @@ Nowadays, it's super fast with:
105103
NULL
106104
```
107105

108-
## `NAMESPACE` File
106+
## `NAMESPACE` file
109107

110108
```{r}
111109
#| echo: true
@@ -118,13 +116,12 @@ export(package_used_second)
118116
export(package_used_third)
119117
```
120118

121-
- Defines the namespace of the package, to work with R's namespace management
122-
system
119+
- Defines the namespace of the package, to work with R's namespace management system
123120
- Namespace directives in this file allow to specify:
124121
- Which objects are exported to users and other packages
125122
- Which are imported from other packages
126123

127-
## `NAMESPACE` File (cont'd)
124+
## `NAMESPACE` file (cont'd)
128125

129126
- Controls the search strategy for variables:
130127
1. Local (in the function body etc.)
@@ -133,34 +130,28 @@ export(package_used_third)
133130
4. Base namespace
134131
5. Normal `search()` path
135132

136-
## `man` Folder
133+
## `man` folder
137134

138-
- Contains documentation files for the objects in the package in the `.Rd`
139-
format
135+
- Contains documentation files for the objects in the package in the `.Rd` format
140136
- The syntax is a bit similar to `LaTeX`
141137
- All user level objects should be documented
142138
- Internal objects don't need to be documented --- but I recommend it!
143-
- Once upon a time, developers would set up these `.Rd` files and the
144-
`NAMESPACE` manually `r emoji::emoji("yawning_face")`
139+
- Once upon a time, developers would set up these `.Rd` files and the `NAMESPACE` manually `r emoji::emoji("yawning_face")`
145140
- Fortunately, nowadays we have `roxygen2`! `r emoji::emoji("rocket")`
146141

147-
## `roxygen2` to the Rescue!
142+
## `roxygen2` to the rescue!
148143

149-
- We can include the documentation source directly in the R script on top of
150-
the objects we are documenting
151-
- Syntax is composed of special comments `#'` and special macros preceded with
152-
`@`
153-
- In RStudio, running Build > More > Document will render the `.Rd` files and
154-
the `NAMESPACE` file for you
144+
- We can include the documentation source directly in the R script on top of the objects we are documenting
145+
- Syntax is composed of special comments `#'` and special macros preceded with `@`
146+
- In RStudio, running Build > More > Document will render the `.Rd` files and the `NAMESPACE` file for you
155147
- Get started with `usethis::use_roxygen_md()`
156-
- Placing your cursor inside a function in RStudio, create a `roxygen2` skeleton
157-
with Code > Insert Roxygen Skeleton
148+
- Placing your cursor inside a function in RStudio, create a `roxygen2` skeleton with Code > Insert Roxygen Skeleton
158149

159150
## Setting up `roxygen2` in your project
160151

161152
![](resources/roxygen2-setting.png){.r-stretch}
162153

163-
## `roxygen2` Source
154+
## `roxygen2` source
164155

165156
`R/my_sum.R`:
166157

@@ -187,7 +178,7 @@ my_sum <- function(x, y) {
187178
}
188179
```
189180

190-
## `roxygen2` Output
181+
## `roxygen2` output
191182

192183
`man/my_sum.Rd`:
193184

@@ -222,7 +213,7 @@ my_sum(1, 2)
222213
}
223214
```
224215

225-
## `roxygen2` Output (cont'd)
216+
## `roxygen2` output (cont'd)
226217

227218
`NAMESPACE`:
228219

@@ -232,7 +223,7 @@ my_sum(1, 2)
232223
export(my_sum)
233224
```
234225

235-
## `tests` Folder
226+
## `tests` folder
236227

237228
- Where store the unit tests covering the functionality of the package
238229
- Get started with `usethis::use_testthat()` and `usethis::use_test()` and
@@ -241,7 +232,7 @@ export(my_sum)
241232
into R scripts directly in `tests` directory
242233
- We will look at unit tests in detail later
243234

244-
## `data` Folder
235+
## `data` folder
245236

246237
- For (example) data that you ship in your package to the user
247238
- Get started with `usethis::use_data()`
@@ -250,7 +241,7 @@ export(my_sum)
250241
- If you generate the example data, save the R script, too
251242
- Put that into `data-raw` folder, start with `usethis::use_data_raw()`
252243

253-
## `inst` Folder
244+
## `inst` folder
254245

255246
- Contents will be copied recursively to installation directory
256247
- Be careful not to interfere with standard folder names
@@ -261,7 +252,7 @@ export(my_sum)
261252
- Create it with `usethis::use_citation()`
262253
- `inst/doc` can contain documentation files (typically `pdf`)
263254

264-
## `src` Folder
255+
## `src` folder
265256

266257
- Contains sources and headers for any code that needs compilation
267258
- Should only contain a single language here
@@ -272,7 +263,7 @@ export(my_sum)
272263
- Wrapping existing libraries for use in R
273264
- Speeding up complex or long computations
274265

275-
## `vignettes` Folder
266+
## `vignettes` folder
276267

277268
- Special case of documentation files (`pdf` or `html`) created by compiling
278269
source files
@@ -283,7 +274,7 @@ export(my_sum)
283274
- Important for the user to understand the high-level ideas
284275
- Complements function-level documentation from our `roxygen2` chunks
285276

286-
## `NEWS` File
277+
## `NEWS` file
287278

288279
- Lists user-visible changes worth mentioning
289280
- In each new release, add items at the top under the version they refer to
@@ -297,7 +288,7 @@ export(my_sum)
297288
- We mentioned before that licensing information is usually included in the `DESCRIPTION` file
298289
- In fact, the `License` field (in standardized form) is mandatory
299290
- Licensing for a package which might be distributed is an important but potentially complex subject
300-
- It is very important to include license information, as otherwise:
291+
- It is very important to include licensing information, as otherwise:
301292
- It may not be possible to use it
302293
- It may not be possible to distribute copies of it
303294
- We are going to talk more about licensing in Chapter 5 later today
@@ -323,9 +314,10 @@ License: Artistic-2.0 | AGPL-3 + file LICENSE
323314
- The optional file `LICENSE`/`LICENCE` contains a copy of the license
324315
- Only include such a file if it is referred to in the `License` field
325316

326-
## Adding a license to your package
317+
## Adding a license to your package {.scrollable}
327318

328319
- Once again, functions from the usethis package simplify this process
320+
329321
- Possible options:
330322
- `usethis::use_mit_license(copyright_holder = NULL)`
331323
- `usethis::use_gpl_license(version = 3, include_future = TRUE)`
@@ -336,18 +328,17 @@ License: Artistic-2.0 | AGPL-3 + file LICENSE
336328
- `usethis::use_ccby_license()`
337329
- `usethis::use_proprietary_license(copyright_holder)`
338330

339-
# Building the Package
331+
# Building the package
340332

341-
## Documenting the Package
333+
## Documenting the package
342334

343335
- The first step is to produce the documentation files and `NAMESPACE`
344336
- In RStudio: Build > More > Document
345337
- In the console: `devtools::document()`
346338

347-
## Checking the Package
339+
## Checking the package
348340

349-
- R comes with pre-defined check command for packages:
350-
"the R package checker" aka `R CMD check`
341+
- R comes with pre-defined check command for packages: "the R package checker" aka `R CMD check`
351342
- About 22 checks are run (so quite a lot), including things like:
352343
- Can the package be installed?
353344
- Is the code syntax ok?
@@ -357,28 +348,26 @@ License: Artistic-2.0 | AGPL-3 + file LICENSE
357348
- In RStudio: Build > Check
358349
- In the console: `devtools::check()`
359350

360-
## Building the Package
351+
## Building the package
361352

362353
- The R package folder can be compressed into a single package file
363354
- Typically we manually only build "source" package
364355
- In RStudio: Build > More > Build Source Package
365356
- In the console: `devtools::build()`
366357
- Makes it easy to share the package with others and submit to CRAN
367358

368-
## Installing the Package
359+
## Installing the package
369360

370-
- R comes with pre-defined install command for packages:
371-
`R CMD INSTALL`
361+
- R comes with pre-defined install command for packages: `R CMD INSTALL`
372362
- In RStudio: Build > Install
373363
- In the console: `devtools::install()`
374-
- Note: During development it's usually sufficient to use Build > More > Load
375-
All
364+
- Note: During development it's usually sufficient to use Build > More > Load All
376365
- Runs `devtools::load_all()`
377366
- Roughly simulates what happens when package would be installed and loaded
378367
- **Unexported** objects and helpers under `tests` will also be available
379368
- Key: much faster!
380369

381-
## Keyboard Shortcuts
370+
## Keyboard shortcuts
382371

383372
- Learning a few keyboard shortcuts can speed up many of the tasks we introduced in this lecture:
384373

@@ -389,7 +378,7 @@ readr::read_csv(here::here("slides/resources/keyboard-shortcuts.csv"), col_types
389378
knitr::kable(align = "ccc")
390379
```
391380

392-
- There are many more – check the [RStudio IDE Documentation](https://docs.posit.co/ide/user/ide/reference/shortcuts.html)
381+
- There are many more – check for instance the [RStudio IDE Documentation](https://docs.posit.co/ide/user/ide/reference/shortcuts.html)
393382

394383
# Exercise
395384

@@ -405,7 +394,7 @@ readr::read_csv(here::here("slides/resources/keyboard-shortcuts.csv"), col_types
405394
1. Run checks
406395
1. Build the package
407396

408-
> We will be using this package throughout the day!
397+
$\leadsto$ We will be using this package throughout the day!
409398

410399
# References
411400

0 commit comments

Comments
 (0)