-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02d_filenaming.qmd
329 lines (175 loc) · 5.76 KB
/
02d_filenaming.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
---
title: "Good File Naming"
author: "Dr Anna Krystallli"
subtitle: "Reproducible Research Data and Project Management in R"
institute: R-RSE
materials_url: https://acce-rrresearch.netlify.app/
format:
revealjs:
logo: assets/logo/r-rse-logo2.png
theme: [default, assets/css/styles.scss, assets/css/reveal.scss]
footer: "[{{< fa home >}}](index.qmd)"
from: markdown+emoji
template-partials:
- assets/layouts/title-slide.html
editor: visual
preload-iframes: true
lightbox: true
execute:
echo: true
message: false
---
## Background
:::: {.columns}
::: {.column width=50%}
### Let's face it...
- There are going to be files
- **LOTS** of files
- The files will **change over time**
- The files will **have relationships to each other**
### It'll probably get complicated
:::
::: {.column width=50%}

:::
::::
## **Strategy against chaos**
### **File organization** and **naming** is a mighty weapon against chaos
- Make a file's **name** and **location** ***VERY INFORMATIVE*** about:
- what it is,
- why it exists,
- how it relates to other things
- The more things are **self-explanatory**, the better.
## File naming
### **Names matter**

## **What works, what doesn't?**
:::: {.columns}
::: {.column width=50%}
**NO**
~~~
myabstract.docx
Joe’s Filenames Use Spaces and Punctuation.xlsx
figure 1.png
fig 2.png
JW7d^(2sl\@deletethisandyourcareerisoverWx2*.txt
~~~
:::
::: {.column width=50%}
**YES**
~~~
2014-06-08_abstract-for-sla.docx
joes-filenames-are-getting-better.xlsx
fig01_scatterplot-talk-length-vs-interest.png
fig02_histogram-talk-attendance.png
1986-01-28_raw-data-from-challenger-o-rings.txt
~~~
:::
::::
## **Three principles for good (file) names**
1. ### **Machine readable**
1. ### **Human readable**
1. ### **Play well with default ordering**
## **Machine readable**
- **Regular expression and globbing friendly**
+ Avoid spaces, punctuation, accented characters, case sensitivity
- **Easy to compute on**
+ Deliberate use of delimiters
## Filtering and search through [Globbing](http://searchsecurity.techtarget.com/definition/globbing)
### **Excerpt of complete file listing:**

## **Example of globbing to filter file listing:**

## **Search using Mac OS Finder search facilities**

## **Search using regex in R**

## **Delimit information with punctuation**
**Deliberate use of `"-"` and `"_"` allows recovery of metadata from the filenames:**
- `"_"` underscore used to delimit units of metadata I want to access later
- `"-"` hyphen used to delimit words so our eyes don't bleed

## Splitting filenames by delimiters

This happens to be `R` but also possible in the `shell`, `Python`, etc.
## **Include important metadata**
e.g. I'm saving a number of files of temperature data extracted at different resolutions (`res`) and for a number of months (`month`). Including these parameters in the filename allows me to use them to target files to read in.
```{r, eval=FALSE}
write.csv(df, paste("variable", res, month, sep ="_"))
df <- read.csv(paste("variable", res, month, sep ="_"))
```
## **Recap: machine readable**
- **Easy to search for files later**
- **Easy to filter file lists based on names**
- **Easy to extract info from file names, e.g. by splitting**
**New to regular expressions and globbing? be kind to yourself and avoid**
+ Spaces in file names
+ Punctuation
+ Accented characters
## **Human readable**
- **Name contains info on content**
- **Connects to concept of a** [***slug***](https://en.wikipedia.org/wiki/Semantic_URL#Slug) **from semantic URLs**
## **Example**
#### **Which set of file(name)s do you want at 3 a.m. before a deadline?**

## **Embrace the slug**
<img src="assets/img/slug_filenames.png" height="400px">
***
### Use slugs to link inputs, scripts & outputs
:::: {.columns}
::: {.column width=50%}
#### **The `R` scripts:**
~~~
01_marshal-data.r
02_pre-dea-filtering.r
03_dea-with-limma-voom.r
04_explore-dea-results.r
90_limma-model-term-name-fiasco.r
~~~
:::
::: {.column width=50%}
#### **The figures left behind:**
~~~
02_pre-dea-filtering-preDE-filtering.png
03-dea-with-limma-voom-voom-plot.png
04_explore-dea-results-focus-term-adjusted-p-values1.png
04_explore-dea-results-focus-term-adjusted-p-values2.png
...
90_limma-model-term-name-fiasco-first-voom.png
90_limma-model-term-name-fiasco-second-voom.png
~~~
:::
::::
## **Recap: Human readable**
- **Easy to figure out what the heck something is, based on its name**
## **Play well with default ordering**
- **Put something numeric first**
- **Use the ISO 8601 standard for dates**
- **Left pad other numbers with zeros**
## Examples
### **Chronological order:**
Use the **ISO 8601** standard for dates: `YYYY-MM-DD`

***

## **Logical order:** Put something numeric first

## Left pad other numbers with zeros

**If you don’t left pad, you get this:**
~~~
10_final-figs-for-publication.R
1_data-cleaning.R
2_fit-model.R
~~~
which is just sad :(
## Recap: Play well with default ordering
- Put something numeric first
- Use the ISO 8601 standard for dates
- Left pad other numbers with zeros
## **Recap: Three principles for (file) names**
1. Machine readable
2. Human readable
3. Play well with default ordering
### Go forth and use awesome file names :)
# Get back [{{< fa home >}}](index.qmd)