-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconductor.Rmd
125 lines (83 loc) · 3.51 KB
/
conductor.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
---
title: "conductor"
author: Raissa L Gill
date: 2023-10-12
description: Conductor notebook for running R projects
---
# Read me!
==============================================================================|
This R notebook contains the following:
* 00 Packages - install and load dependencies, including those currently saved
in your project's lockfile and additional packages.
* 01 Code - place-holder for your code
* 02 Style - format code in your project's directory
More information on coding style can be found here: style.tidyverse.org
# 00 Packages
==============================================================================|
```{r Current dependencies}
# Install and load packages in project's lockfile
source("./00-code/00-install-dependencies.R", chdir = TRUE)
```
```{r Add/load packages during a coding session}
# As you progress and need additional packages for your project, install and
# load them here by following these steps:
# 1. Add names of any packages to the list_packages() vector below:
# 2. Run this chunk.
# The code:
list_packages <- c("ggplot2", "ggpubr")
install_packages <- list_packages[!list_packages %in% installed.packages()]
for (lib in install_packages) install.packages(lib, dependencies = TRUE)
lapply(list_packages, library, character.only = TRUE)
```
```{r Save packages after a coding session}
# Save any extra packages in your project's lockfile for future use:
# 1. Navigate to 00-R-code from Files pane > open "Install-dependencies.R".
# 2. Add extra package names to the list_packages() vector.
# 3. Run the script > save & close.
# 4. In this chunk, remove package name(s) from the list_packages() vector.
# 5. Run this chunk > save.
```
# 01 Code
==============================================================================|
```{r Begin writing your code}
# I am coding now
# So fun
```
```{r Move/save code as you complete code}
# As you complete stages in the analysis, move your code out of Conductor.Rmd
# into their own separate files. I've created two templates in 00-R-code that
# you can use to create new files with nice structure and formatting:
# Template-R-script.R and Template-R-notebook.Rmd.
# Save your code as separate files in the 00-R-code directory - index these
# (00, 01 etc.) or create sub-folders if needed to keep track of code. Don't
# forget to use good file naming conventions (e.g., tidyverse).
```
```{r Source code as needed}
# Use source() functions to stitch your code together and run as needed -
# source() uses relative pathing from the root folder (via ./) to locate and
# run code. E.g. source("./00-R-code/Install-dependencies.R", chdir = TRUE).
```
# 02 Style
==============================================================================|
```{r Format code as you complete stages}
# !!! WARNING !!!
# Run this chunk line by line and follow it step-by-step!
# 1. Commit your changes to GitHub now!
# 2. Select/load style guide
if (FALSE) {
# First time
lintr::use_lintr(type = "tidyverse") # Can change the style here
# Thereafter
lintr::lint_dir()
}
# 3. Make note of which files in your project need styling
lintr::lint_dir()
# 4. Format all code in your project according to the selected style guide
styler::style_dir("./")
# 5. Check the modified code from above to ensure it works and you're
# happy with any change(s).
# 6. Check directory again for any changes requiring user modification
lintr::lint_dir()
# 7. Make the manual modification(s) from above
# 8. When you're happy everything works, commit your changes to GitHub.
```