class: center, middle, inverse, title-slide .title[ # Introduction to the {targets} package ] .subtitle[ ## Reproducible Scientific Workflows in R ] .author[ ### Ernest Guevarra ] .date[ ### 2024-02-05 ] --- class: inverse, middle .pull-left[ Masons, when they start upon a building, Are careful to test out the scaffolding; Make sure that planks won't slip at busy points, Secure all ladders, tighten bolted joints. And yet all this comes down when the job's done Showing off walls of sure and solid stone. ] .pull-right[ So if, my dear, there sometimes seem to be Old bridges breaking between you and me Never fear. We may let the scaffolds fall Confident that we have built our wall. - "Scaffolding" by Seamus Heaney, 1939-2013 ] --- # Outline * Concepts on scientific workflows * The `{targets}` package * Practical session --- class: inverse, center, middle # Concepts on scientific workflows --- class: inverse, center, middle # Concept #1: Reproducibility, reproducibility, reproducibility! --- class: center, middle # Most important tool for Reproducible Research is the mindset, when starting, taht the end product will be reproducible. [Keith Baggerly](http://odin.mdacc.tmc.edu/~kabaggerly/), via [@kwbroman](https://twitter.com/kwbrowman) [tweet](https://twitter.com/kwbroman/status/667735926915731457) --- class: inverse, center, middle # Concept #2: Organisation --- class:: center, middle # File organization and naming are powerful weapons against chaos. [@JennyBryan](https://twitter.com/jennybryan) --- background-color: #FFFFFF background-image: url(images/file_organisation.png) background-size: 90% --- class: inverse, center, middle # Concept #3: DRY - Don't repeat yourself --- class: center, middle # Don't repeat yourself. It's not only repetitive, it's redundant, and people have heard it before. Lemony Snicket --- class: center, middle # "You should consider writing a function whenever you’ve copied and pasted a block of code more than twice (i.e. you now have three copies of the same code)" --- class: inverse, center, middle # Challenges with scientific workflows --- # Sisyphean loop .pull-left[ <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Nekyia_Staatliche_Antikensammlungen_1494_n2.jpg/582px-Nekyia_Staatliche_Antikensammlungen_1494_n2.jpg" width="450px" style="vertical-align:middle" /> ] .pull-right[ 1. Launch the code. 2. Wait while it runs. 3. Discover an issue. 4. Restart from scratch. ] --- # The `{targets}` package .pull-left[ <img src="https://github.com/ropensci/targets/raw/main/man/figures/logo.png" width="400px" style="vertical-align:middle" /> ] .pull-right[ * a pipeline toolkit for Statistics and data science in R * maintain a reproducible workflow without repeating yourself * learns how your workflow fits together * skips costly runtime for tasks that are already up-to-date * runs only the necessary computation * supports implicit parallel computing * abstracts files as R objects * shows tangible evidence that the results match the underlying code and data ] --- # `{targets}` file organisation .pull-left[ .center[![](images/targets_file_organisation.png)] ] .pull-right[ * this is a typical file structure with user-defined components of any project-oriented workflow * the `_targets.R` file, however, is special and specific to a `{targets}` workflow - it is the target script file * the target script file should be in the project's root directory ] --- # `{targets}` script file .pull-left[ .center[![](images/target_script.png)] ] .pull-right[ * Load the packages required (1) * Load custom functions (1) * Define individual targets - intermediate step of the workflow (2) * End with a list of targets objects ] --- background-color: #FFFFFF background-image: url(images/workflow.png) background-size: 60% # `{targets}` workflow --- class: inverse, center, middle # Questions? --- class: inverse, center, middle # Practical session ## We will all continue to go through Exercise #1 in the [Practical R for Epidemiologists](https://practical-r.org/exercise1.html) book --- class: inverse, center, middle # Questions? --- class: inverse, center, middle # Thank you! Slides can be viewed at https://oxford-ihtm.io/open-reproducible-science/session8.html PDF version of slides can be downloaded at https://oxford-ihtm.io/open-reproducible-science/pdf/session8-reproducible-scientific-workflows.pdf R scripts for slides available [here](https://github.com/OxfordIHTM/open-reproducible-science/blob/main/session8.Rmd)