-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.qmd
64 lines (41 loc) · 1.88 KB
/
style.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
---
execute:
eval: false
---
# ESQlabs' R Style Guide
At ESQlabs, we follow the [tidyverse style guide](https://style.tidyverse.org) with very few changes. The following sections outline the most important differences with the Tidyverse guide.
## Syntax
### Naming Conventions
For simplicity, users should use `snake_case` as recommended by the tidyverse style (this is not the case for developers that should follow the [OSPS-R coding standards](https://github.com/Open-Systems-Pharmacology/Suite/blob/develop/CODING_STANDARDS_R.md)).
However the naming style depends on the type of object:
- Variable and function names should use only letters and numbers. Use `snake_case` to separate words within a name:
```{r}
# Good
fit_model <- function() {
# code
}
results_df <- data.frame()
```
- True constant variables should use `ALL_CAPS` casing:
```{r}
# Good
CONSTANT_VAR <- 1
```
- Use short meaningful and understandable names. The code should read as a story and only some well-known abbreviations should be used:
```{r}
# Good
pk_data <- read_excel("pkDataFile.xls")
# Bad
pharmacokinetics_data <- read_excel("pkDataFile.xls") # Too long
```
### Spacing
Because it is not explicitly said in the tidyverse guideline and for improved code readability, use the following indentation settings:
- Use spaces instead of tabs
- Use indentation width of 2
You can check that these settings are correctly set in Tools \> Global Options \> Code \> Editing:
![](images/indent_settings.png){width="130"}
## Functions
### `return()`
Prefer using `return()` for explicitly returning result, although you can rely on R to implicitly return the result of the last evaluated expression in a function.
## Line length
Avoid having long lines. Restrict yourself to 120 characters (instead of the usual limit of 80 characters).