You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Some good coding practices {background-color=#FFCD00}
60
+
61
+
## R projects and working directories
62
+
63
+
When you start programming for yourself:
64
+
65
+
- Create a folder dedicated to your project
66
+
- Start a new R project: **File > New Project > Existing Directory**
67
+
- An `.RProj` file will be created
68
+
69
+
. . .
70
+
71
+
Advantages:
72
+
73
+
- Automatically set your working directory to that folder
74
+
- Automatically retrieve only the history and objects from that R project
75
+
- More reproducible (relative vs. absolute paths)
76
+
77
+
```r
78
+
getwd()
79
+
```
80
+
81
+
## Comments
82
+
83
+
If a line of R code starts with `#`, it is ignored.
84
+
85
+
- Help your future you and collaborators/supervisors understand what your code does
86
+
- Explain (the purpose of) code that is not self-explanatory
87
+
- Comment and un-comment to debug code without having to delete it[^1]
88
+
89
+
```{r}
90
+
# Print a very important line
91
+
print("A very important line")
92
+
```
93
+
94
+
[^1]: You should delete non-working code when done debugging though.
95
+
59
96
## The Data Science workflow
60
97
61
98
](https://d33wubrfki0l68.cloudfront.net/571b056757d68e6df81a3e3853f54d3c76ad6efc/32d37/diagrams/data-science.png"The data science workflow."){fig-align="center"}
@@ -85,8 +122,8 @@ This means that often the results of one step will be the input for the next
85
122
::: {.incremental}
86
123
1. Read a file into R
87
124
2. Clean the data:
88
-
- Filter on relevant rows
89
125
- Select only relevant columns
126
+
- Filter on relevant rows
90
127
3. Calculate a new column
91
128
4. Rename a column
92
129
5. Put the dataframe into a long (tidy) format
@@ -111,26 +148,6 @@ This means that often the results of one step will be the input for the next
111
148
112
149

113
150
114
-
## R projects and working directories
115
-
116
-
When you start programming for yourself:
117
-
118
-
- Create a folder dedicated to your project
119
-
- Start a new R project: **File > New Project > Existing Directory**
120
-
- An `.RProj` file will be created
121
-
122
-
. . .
123
-
124
-
Advantages:
125
-
126
-
- Automatically set your working directory to that folder
127
-
- Automatically retrieve only the history and objects from that R project
0 commit comments