README.md 2.98 KB
Newer Older
Jason Rigby's avatar
Jason Rigby committed
1
# Installation
Jason Rigby's avatar
Jason Rigby committed
2
To install this package directly from git, you will first need the devtools and getPass packages if not already installed:
Jason Rigby's avatar
Jason Rigby committed
3
```
Jason Rigby's avatar
Jason Rigby committed
4
install.packages(c("devtools", "getPass"))
Jason Rigby's avatar
Jason Rigby committed
5
6
```

Jason Rigby's avatar
Jason Rigby committed
7
8
Then, the ASPREE package itself can be installed using the following command:
```
Jason Rigby's avatar
Jason Rigby committed
9
username <- "your_monash_username"
Jason Rigby's avatar
Jason Rigby committed
10
devtools::install_git("https://gitlab.erc.monash.edu.au/aspree/aspree-r-package.git",
Jason Rigby's avatar
Jason Rigby committed
11
    credentials = git2r::cred_user_pass(username, getPass::getPass()))
Jason Rigby's avatar
Jason Rigby committed
12
13
```
You will be prompted for your Monash GitLab credentials before installation proceeds.
Jason Rigby's avatar
Jason Rigby committed
14

Jason Rigby's avatar
Jason Rigby committed
15
16
17
18
19
20
21
22
Here's an example using the ASPREE library to retrieve ASPREE XT consent status:
```
library(aspree)
library(dplyr)

aspreeConsent <- aspreeDb("ASPREE Data Snapshot") %>% getXTConsent()
```

Jason Rigby's avatar
Jason Rigby committed
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
# Development

Recommended reading: [the devtools cheatsheet](https://www.rstudio.com/wp-content/uploads/2015/03/devtools-cheatsheet.pdf)

## Dependencies
Package dependencies must be declared in the [DESCRIPTION](DESCRIPTION) file. Use the `devtools::use_package()` function to add these automatically.

## Documentation
Use the `roxygen` to document every function that needs to be visible to the end-user. Roxygen documentation can be provided by writing specially formatted comments above each function. An example from [the devtools cheatsheet](https://www.rstudio.com/wp-content/uploads/2015/03/devtools-cheatsheet.pdf):

```
#' Add together two numbers.
#'
#' @param x A number.
#' @param y A number.
#' @return The sum of \code{x} and \code{y}.
#' @examples
#' add(1, 1)
#' @export
add <- function(x, y) {
    x + y
}
```

The documentation should describe at least
* What the function does
* Each function parameter
* The data returned

If the function needs to be visible to the end user, it should also tag the function with `@export`.

Once the functions are written, tested and documented, `devtools::document()` should be run. This will regenerate `NAMESPACE` and the markdown documents in the `man` directory appropriately.

## Testing and quality control
All functions should be appropriately unit tested, ideally using the automated test framework `testthat`. More detail information regarding tests can be found in the [tests/testthat](tests/testthat) subdirectory.

Tests should be written in a way that:
* will detect when errors in dependent functions or the underlying data arises, e.g. most functions that return ASPREE data will have 19,114 rows (one per participant)
* tests the behaviour when both valid and invalid data is provided, e.g. `sqrt(x)` should not be defined if a negative input is given
* never has an external dependency, e.g. pre-canned (fake) data should be provided to simulate database access

All changes should be proposed via GitLab merge requests and reviewed prior to acceptance. [Git `tags`](https://git-scm.com/book/en/v2/Git-Basics-Tagging) should be used to mark major releases to allow for reproducible analysis. Insofar as practical, git commits merged into the master branch should be squashed into units that sensibly describe their net effect.