A gentle guide to using the {targets} package for analytic pipelines

Newcastle, UK

Nicholas Tierney

The Kids Institute, Australia

2024-09-03

Motivation

  • Data analysis is interactive and messy
  • How to know if it is up-to-date? Better re-run…
  • Months later, how did you do things? Better re-run…
  • Thinking about data analysis deserves inherent structure
  • You are always collaborating with your future self
  • {targets} is a way to manage complexity
    • It’s also a mindset, a philosophy.

I have 3 goals

  1. Convince you {targets} is worth learning
  2. Convince you that you can use it
  3. For you to feel more confident writing functions

Audience

  1. Who uses R here?
  2. Have you used targets?

How this will all flow

  • Talk / analysis is on github: njtierney/gentle-intro-targets
  • Live coding (from scratch) a data analysis
  • There is no “Here’s one I prepared earlier”
    • (Although I have practiced the live coding)
  • Please ask questions throughout
  • Ask on Canapii for deeper questions
  • Also please feel free to yell out and we can transcribe/repeat
  • Analysis is a little simplified
  • “What questions do you have?”

How to follow along

  • This was not designed as a follow along exercise
    • You are welcome to try!
  • You might be best served to observe, take notes, ask questions
  • Please do ask questions

Data analysis: penguins

begin_demo(timer!)

Intermission: checking in

  • What things could we do to tidy up this data analysis?
  • What should we do from here?
  • What problems might come up in this data analysis?
  • Demonstrating debugging in targets
  • Reading/Writing CSV
  • Saving plots

end_demo()

Takeaways: functions

  • Write functions to think about solving problems
  • Good functions do the following:
    • Manage complexity
    • Explain and express ideas
    • Can be individually reasoned with
    • Take iteration
  • Functions can help plan out intent
  • {fnmate} keyboard shortcut for writing functions helps a lot

Takeaways: {targets}

  • No problem is too small for targets
  • Use tflow::use_tflow() to setup a project
  • Use a quarto/rmd as a scratchpad
  • Keyboard shortcuts for load/make targets

Some things I might not have gotten to

  • Demonstrating debugging in targets
  • Reading/Writing CSV
  • Saving plots

Thanks

  • Will Landau
  • Miles McBain
  • Nick Golding
  • Eric Scott

Resources

Colophon

Learning more

targets

talk link

njtierney

nicholas.tierney@gmail.com

End.