class: center, middle, inverse, title-slide # > Β Β π
> Β Β Project structure ###
Danielle Navarro
--- layout: true <div class="my-footer"> <span> <a href="https://slides.djnavarro.net/project-structure" target="_blank">slides.djnavarro.net/project-structure</a> </span> </div> --- class: middle, inverse ## What are we going to cover? - Naming files - Project structure --- class: middle, inverse ## What is the assumed knowledge? - This is an introductory unit - Contains almost no programming content at all --- class: middle, inverse ## Where can I find the resources? - These slides: [slides.djnavarro.net/project-structure](https://slides.djnavarro.net/project-structure) - YouTube videos: [youtube.djnavarro.net/project-structure](https://youtube.djnavarro.net/project-structure) --- class: middle, inverse background-image: url("img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-primary[.plainwhite[1]] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.plainwhite[Naming things]]] ] --- class: middle, inverse .hand[Acknowledgment] - "Everything I know is from Jenny Bryan" - This section is based on (i.e., shamelessly mimics) her slides - https://speakerdeck.com/jennybc/how-to-name-files --- class: middle .hand[ βTis but thy name that is my enemy;<br> Thou art thyself, though not a Montague.<br> Whatβs Montague? It is nor hand, nor foot,<br> Nor arm, nor face, nor any other part<br> Belonging to a man. O, be some other name!<br> Whatβs in a name? That which we call a rose<br> By any other name would smell as sweet;<br> So Romeo would, were he not Romeo callβd,<br> Retain that dear perfection which he owes<br> Without that title. Romeo, doff thy name;<br> And for thy name, which is no part of thee,<br> Take all myself. ] --- class: middle, inverse .hand[This isn't true for file names!] --- .hand[Some file names are good β ] - `reading01_shakespeare_romeo-and-juliet_act01.docx` - `reading01_shakespeare_romeo-and-juliet_act02.docx` - `reading01_shakespeare_romeo-and-juliet_act03.docx` - `reading02_shakespeare_othello.docx` - `reading19_plath_the-bell-jar.docx` -- .hand[Other file names are baaaaaad β] - `Romeo and Juliet Act 1.docx` - `Romeo and juliet act 2.docx` - `Shakespeare RJ act3.docx` - `shakespeare othello I think?.docx` - `belljar plath (1).docx` --- class: middle, inverse .hand[Three principles to be kind to yourself] - Be nice to machines - Be nice to humans - Make sorting and searching easy --- class: middle, inverse background-image: url("img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-primary[.plainwhite[2]] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.plainwhite[Names machines like]]] ] --- .hand[Don't leave white space] - Machines sometimes get confused by spaces - Easier to write code when files don't have spaces -- - β `romeo-and-juliet_act01.docx` - β `midsummer-nights-dream.docx` - β `romeo and juliet act 1.docx` - β `midsummer nights dream.docx` --- .hand[Use letters, numbers, hyphens and underscores... that's it] - Machines sometimes get confused by special characters - Some characters have special meaning, e.g., `^.*?+|$` - If you can, avoid accents `Γ±` (but consider accessibility!) -- - β `what-the-cat.docx` - β `essay_romeo-and-juliet_draft01.docx` - β `what-the-cat?.docx` - β `essay "romeo and juliet" draft01.docx` - β `essay "romeo and juliet" draft01(1).docx` --- .hand[Don't assume case is meaningful] - Some operating systems treat `a` and `A` the same - Some operating systems treat `a` and `A` differently - Never have two files that differ only in case - Be consistent -- - β `othello.docx` - β `romeo-and-juliet.docx` - β `othello.docx` - β `Othello.docx` - β `Romeo-and-juliet.docx` --- .hand[Use separator characters wisely] - Use hyphen `-` to mean "different words that are part of the same chunk" - Use underscore `_` to separate different chunks -- - Chunk: [identifier] `reading01`, `reading02`, etc - Chunk: [author] `shakespeare`, `plath`, etc - Chunk: [title] `othello`, `the-bell-jar`, etc - Chunk: [section] `act01`, `act02`, etc -- - Order: [identifier] [author] [title] [section(optional)] - β `reading01_shakespeare_romeo-and-juliet_act01.docx` - β `reading01_shakespeare_romeo-and-juliet_act02.docx` - β `reading02_shakespeare_othello.docx` - β `reading19_plath_the-bell-jar.docx` --- class: middle, inverse background-image: url("img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-primary[.plainwhite[3]] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.plainwhite[Names humans like]]] ] --- .hand[It's 3am and the project is due... do you want these files?] - `01.R` - `02.R` - `notes.txt` - `2b.R` - `notes.docx` -- .hand[or these?] - `analysis01_descriptive-statistics.R` - `analysis02_preregistered-analysis.R` - `notes01_realising-the-problem.txt` - `analysis03_departing-from-the-plan.R` - `notes02_tentative-write-up.docx` --- class: inverse .hand[Love the slug π] <code class ='r hljs remark-code'>"analysis01<span style='background-color:#ffff7f'>_descriptive-statistics</span>.R"<br>"analysis02<span style='background-color:#ffff7f'>_preregistered-analysis</span>.R"<br>"notes01<span style='background-color:#ffff7f'>_realising-the-problem</span>.txt"<br>"analysis03<span style='background-color:#ffff7f'>_departing-from-the-plan</span>.R"<br>"notes02<span style='background-color:#ffff7f'>_tentative-write-up</span>.docx"</code> -- - Concise, meaningful description - Usually appended to the end --- class: middle, inverse background-image: url("img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-primary[.plainwhite[4]] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.plainwhite[Easy sort and search]]] ] --- .hand[File names sometimes need to include dates<br>... but these dates don't sort in chronological order π] - `1-April-2012.R` - `1-Jan-2009.R` - `1-Jan-2012.R` - `12-Jan-2012.R` - `2-Jan-2012.R` - `31-Dec-2009.R` --- .hand[Happily, these dates do! π] - `2009-01-01.R` - `2009-12-01.R` - `2012-01-01.R` - `2012-01-02.R` - `2012-04-01.R` -- .hand[Key principle with dates...] - Dates should follow the `YYYY-MM-DD` format - Known as the ISO 8601 standard --- class: inverse .hand[Place dates before slugs to preserve chronology...] <code class ='r hljs remark-code'><span style='background-color:#ffff7f'>"2009-01-01</span>_original-analysis.R"<br><span style='background-color:#ffff7f'>"2009-12-01</span>_minor-changes-to-original.R"<br><span style='background-color:#ffff7f'>"2012-01-01</span>_analysis-at-2-year-follow-up.R"<br><span style='background-color:#ffff7f'>"2012-01-02</span>_minor-changes-to-follow-up.R"<br><span style='background-color:#ffff7f'>"2012-04-01</span>_combined-original-and-follow-up.R"</code> --- class: inverse .hand[... and the slugs will tell a story!] <code class ='r hljs remark-code'>"2009-01-01<span style='background-color:#ffff7f'>_original-analysis</span>.R"<br>"2009-12-01<span style='background-color:#ffff7f'>_minor-changes-to-original</span>.R"<br>"2012-01-01<span style='background-color:#ffff7f'>_analysis-at-2-year-follow-up</span>.R"<br>"2012-01-02<span style='background-color:#ffff7f'>_minor-changes-to-follow-up</span>.R"<br>"2012-04-01<span style='background-color:#ffff7f'>_combined-original-and-follow-up</span>.R"</code> --- .hand[Use numbers as a prefix to order files] - `01_preface.docx` - `02_introduction.docx` - `03_method.docx` - etc... - `19_appendix-09.docx` - `20_appendix-10.docx` - `21_appendix-11.docx` -- - Left pad with `0` so that all numbers have same length - Numbers are more robust than letters (alphabetical order varies) --- .hand[Include keywords...] - `reading01_shakespeare_romeo-and-juliet_act01.docx` - `reading01_shakespeare_romeo-and-juliet_act02.docx` - `reading01_shakespeare_romeo-and-juliet_act03.docx` - `reading02_shakespeare_othello.docx` - `reading19_plath_the-bell-jar.docx` - `notes02_shakespeare_othello.docx` - `notes19_plath_the-bell-jar.docx` -- .hand[... to let computer find files] - <code>reading19_<b>plath</b>_the-bell-jar.docx</code> - <code>notes19_<b>plath</b>_the-bell-jar.docx</code> --- .hand[Include keywords...] - `reading01_shakespeare_romeo-and-juliet_act01.docx` - `reading01_shakespeare_romeo-and-juliet_act02.docx` - `reading01_shakespeare_romeo-and-juliet_act03.docx` - `reading02_shakespeare_othello.docx` - `reading19_plath_the-bell-jar.docx` - `notes02_shakespeare_othello.docx` - `notes19_plath_the-bell-jar.docx` .hand[... to let computer find files] - <code><b>notes</b>02_shakespeare_othello.docx</code> - <code><b>notes</b>19_plath_the-bell-jar.docx</code> --- class: middle, inverse background-image: url("img/manuel-santolaria-ls2vGs4sLCU-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-secondary[5] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.secondary[Project structure]]] ] --- class: middle, inverse .hand[Three more principles to be kind to yourself] - Understand file paths - Use project templates - Use README files --- class: middle, inverse background-image: url("img/manuel-santolaria-ls2vGs4sLCU-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-secondary[6] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.secondary[File paths]]] ] --- class: inverse .hand[Files inside folders: an aging metaphor!] <img src="img/wesley-tingey-snNHKZ-mGfE-unsplash.jpg" width="700" /> --- class: inverse .hand[Three files inside one folder] - π <code>.plainwhite[project]</code> - π <code>.plainwhite[01_initial-plan.docx]</code> - π <code>.plainwhite[02_data-collection.R]</code> - π <code>.plainwhite[03_initial-analysis.R]</code> -- <br> .hand[The "file paths" are written like this...] - <code>.plainwhite[project<b>/</b>01_initial-plan.docx]</code> - <code>.plainwhite[project<b>/</b>02_data-collection.R]</code> - <code>.plainwhite[project<b>/</b>03_initial-analysis.R]</code> --- class: inverse .hand[Three files inside one folder] - π <code>.plainwhite[project]</code> - π <code>.plainwhite[01_initial-plan.docx]</code> - π <code>.plainwhite[02_data-collection.R]</code> - π <code>.plainwhite[03_initial-analysis.R]</code> <br> .hand[Except on Windows... π€¦] - <code>.plainwhite[project<b>\\</b>01_initial-plan.docx]</code> - <code>.plainwhite[project<b>\\</b>02_data-collection.R]</code> - <code>.plainwhite[project<b>\\</b>03_initial-analysis.R]</code> --- class: inverse .hand[Folders inside folders creates a "file tree"...] - π <code>.plainwhite[project]</code> - π <code>.plainwhite[overview.docx]</code> - π <code>.plainwhite[data]</code> - π <code><span style="color:white">data_ex01.csv</span></code> - π <code><span style="color:white">data_ex02.csv</span></code> - π <code>.plainwhite[analysis]</code> - π <code><span style="color:white">ex01_01_descriptive-statistics.R</span></code> - π <code><span style="color:white">ex01_02_inferential-statistics.R</span></code> - π <code><span style="color:white">ex02_01_descriptive-statistics.R</span></code> - π <code><span style="color:white">ex02_02_inferential-statistics.R</span></code> - π <code>.plainwhite[report]</code> - π <code><span style="color:white">2021-03-11_report_getting-started.docx</span></code> --- class: inverse .hand[Paths for all files in this tree] - <code>.plainwhite[project/overview.docx]</code> - <code><span style="color:white">project/data/data_ex01.csv</span></code> - <code><span style="color:white">project/data/data_ex02.csv</span></code> - <code><span style="color:white">project/analysis/ex01_01_descriptive-statistics.R</span></code> - <code><span style="color:white">project/analysis/ex01_02_inferential-statistics.R</span></code> - <code><span style="color:white">project/analysis/ex02_01_descriptive-statistics.R</span></code> - <code><span style="color:white">project/analysis/ex02_02_inferential-statistics.R</span></code> - <code><span style="color:white">project/report/2021-03-11_report_getting-started.docx</span></code> --- class: inverse .hand[A tiny bit of R applied to the project containing these slides...] .pull-left-wide[ ```r list.files(recursive = TRUE) ``` ``` ## [1] "example-template.zip" ## [2] "header.html" ## [3] "img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg" ## [4] "img/jessica-lee-o5GGlwHfff8-unsplash.jpg" ## [5] "img/manuel-santolaria-ls2vGs4sLCU-unsplash.jpg" ## [6] "img/stil-wtqe5nd5MYk-unsplash.jpg" ## [7] "img/twitter-image.png" ## [8] "img/vu-anh-ThyBKNya1yY-unsplash.jpg" ## [9] "img/wesley-tingey-snNHKZ-mGfE-unsplash.jpg" ## [10] "index.html" ## [11] "index.Rmd" ## [12] "libs/font-awesome/css/all.css" ## [13] "libs/font-awesome/css/v4-shims.css" ## [14] "libs/font-awesome/webfonts/fa-brands-400.eot" ## [15] "libs/font-awesome/webfonts/fa-brands-400.svg" ``` ``` ## ...the real output is over 15000 files! ``` ] --- class: inverse .hand[...to find the image credits by searching for a keyword!] .pull-left-wide[ ```r list.files(pattern = "unsplash", recursive = TRUE) ``` ``` ## [1] "img/free-to-use-sounds-xbHgspX4_nc-unsplash.jpg" ## [2] "img/jessica-lee-o5GGlwHfff8-unsplash.jpg" ## [3] "img/manuel-santolaria-ls2vGs4sLCU-unsplash.jpg" ## [4] "img/stil-wtqe5nd5MYk-unsplash.jpg" ## [5] "img/vu-anh-ThyBKNya1yY-unsplash.jpg" ## [6] "img/wesley-tingey-snNHKZ-mGfE-unsplash.jpg" ``` ] -- .pull-left-wide[ β€οΈ β€οΈ β€οΈ ] --- class: middle, inverse background-image: url("img/manuel-santolaria-ls2vGs4sLCU-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-secondary[7] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.secondary[Templating]]] ] --- class: inverse .hand[Templates are "blank" projects] - Folder structure already exists - Starter files already included - Instructions are already included -- .hand[Allows you to "start clean"] - Make a copy of the template - Rename files as needed - Start work! --- class: middle, inverse background-image: url("img/stil-wtqe5nd5MYk-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-secondary[8] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.secondary[README]]] ] --- class: inverse .hand[Wait... instructions already included?] - Most folders should have a <code>.plainwhite[README.txt]</code> or <code>.plainwhite[README.md]</code> file - Simple text file explaining what's in the folder and what it's for -- - In the finished project the README files help your users navigate - In your project template the README files contain instructions to you! --- class: middle .hand[Okay, let's design a project template ourselves!] --- class: middle, inverse ## The example template we just made https://slides.djnavarro.net/project-structure/example-template.zip <br> ## A more realistic template I use sometimes https://github.com/djnavarro/newproject/ --- class: middle, inverse background-image: url("img/vu-anh-ThyBKNya1yY-unsplash.jpg") background-size: cover .pull-left-narrow[ .huge-secondary[9] ] .pull-right-wide[ <br><br><br> .larger[.embolden[.secondary[Where do projects live?]]] ] --- class: inverse .hand[Let's go back to file paths for a moment] - Every user has a "home" folder - On windows it might be <code>.plainwhite[C:\Users\danielle]</code> - On a mac it might be <code>.plainwhite[/Users/danielle]</code> - On ubuntu it might be <code>.plainwhite[/home/danielle]</code> -- <br> - User files and folders are inside the user folder - The Desktop is usually <code>.plainwhite[danielle/Desktop]</code> - The Downloads folder is usually <code>.plainwhite[danielle/Downloads]</code> - If you use Dropbox it is usually <code>.plainwhite[danielle/Dropbox]</code> --- class: inverse .hand[There are good places β and bad places β] .pull-left[ ![](https://media.giphy.com/media/l3mZliqXpqkVkkQYE/giphy.gif)<!-- --> ] --- class: inverse .hand[There are good places β and bad places β] .pull-left[ ![](https://media.giphy.com/media/3o6fIX5mC1mSgNU0BW/giphy.gif)<!-- --> ] .pull-right[ - β The Desktop - β The Downloads folder - β Stored with non-projects - β Places that aren't backed up ] --- class: inverse .hand[Cloud services often make good places β ] - β <code>.plainwhite[C:\Users\danielle\OneDrive\projects]</code> - β <code>.plainwhite[/Users/danielle/Dropbox/projects]</code> - β <code>.plainwhite[/home/danielle/Dropbox/projects]</code> -- <br> - π this is a folder on your computer that is automatically synchronised - β Dropbox/OneDrive/etc app ensures your files are the same everywhere - β the service is designed to be user friendly - β you don't get to go "back in time" very far --- class: inverse .hand[Time travel... why?] .pull-left[ ![](https://media.giphy.com/media/efU9WbFkGP9NAkLOWn/giphy.gif)<!-- --> ] -- .pull-right[ - You've made a huge mistake and need to revert - You want to check the order you did things ] --- class: inverse .hand[Three ways to get yourself a TARDIS] .pull-left[ ![](https://media.giphy.com/media/efU9WbFkGP9NAkLOWn/giphy.gif)<!-- --> ] .pull-right[ - Special app (e.g., Time Machine) - Employer backup to server - Version control with git/GitHub ] --- class: inverse .hand[Everyone organises differently, here's mine... βοΈ] .pull-left[ - π <code>.plainwhite[danielle]</code> - π <code>.plainwhite[Dropbox]</code> - π <code>.plainwhite[GitHub]</code> ] -- .pull-right[ - My workflow is different for GitHub versus Dropbox - So I keep these two separated from the start ] --- class: inverse .hand[Everyone organises differently, here's mine... βοΈ] .pull-left[ - π <code><span style="color:white">danielle</span></code> - π <code><span style="color:white">Dropbox</span></code> - π <code><span style="color:white">Work</span></code> - π <code><span style="color:white">administration</span></code> - π <code><span style="color:white">archives</span></code> - π <code><span style="color:white">cheatsheets</span></code> - π <code><span style="color:white">projects</span></code> - π <code><span style="color:white">teaching</span></code> - π <code><span style="color:white">GitHub</span></code> ] -- .pull-right[ - Note the archives folder! - Completed content is not deleted - It is zipped and moved to archives - My archives go back to 1998 - Yes I am old π ] --- class: inverse .hand[Everyone organises differently, here's mine... βοΈ] .pull-left[ - π <code><span style="color:white">danielle</span></code> - π <code><span style="color:white">Dropbox</span></code> - π <code><span style="color:white">GitHub</span></code> - π <code><span style="color:white">archive</span></code> - π <code><span style="color:white">artwork</span></code> - π <code><span style="color:white">other</span></code> - π <code><span style="color:white">projects</span></code> - π <code><span style="color:white">sites</span></code> - π <code><span style="color:white">slides</span></code> - π <code><span style="color:white">teaching</span></code> ] -- .pull-right[ - Similar organisation, not the same - Yours might be different too! - Key principle: *think* about it π€ ] --- class: inverse .hand[Something to think about...] - A project should not "care" where it lives - Suppose my project folder is <code><span style="color:white">floof</span></code> - It currently lives at <code><span style="color:white">/home/danielle/Dropbox/floof</span></code> -- <br> .hand[Will everything still work if...] - ... I move it to <code><span style="color:white">/home/danielle/GitHub/floof</span></code>? - ... I copy it onto a different computer? - ... the new computer runs a different operating system? -- <br> .hand[... Let's leave that question until later!] --- class: middle, inverse background-image: url("img/jessica-lee-o5GGlwHfff8-unsplash.jpg") background-size: cover .hand-primary[<br><br><br><br>... and we're done! explore and be organised! β€οΈ]