drakeme(): Quickly jump into a drake workflow

flowme::drakeme()

flowme::drakeme() includes our boilerplate code for drake-powered projects in your current session. It is originally based on McBain’s dflow and it is tailored to our report-generating projects.

Aims of this boilerplate

We put together this template, mainly, to:

  • A1: Make it easy to jump into a drake workflow. In particular, for those used to the analysis as R package approach.
  • A2: Make it easy and one-sight-clear what the project is all about. In particular, for a new person collaborating or overtaking the project (which, of course, may well be future you).
  • A3: Cover the most common use case we have, which is a data analysis project that ends up in a somewhat beefy report (as opposed to, for example, a ML project that ends up putting a model up in “production”).

Features to achieve those aims

These are the key features to achieve those aims (admittedly, some could be highly controversial. Yet, they work for us).

  • Fully functional drake project at the push of a button: once installed, flowme helps you setup a drake project with one-function call (flowme::drakeme()), including all required packages. It will get you started with a “hello world” project that you can actually run (drake::r_make()) and see the output. A1

  • devtools::load_all() friendly: flowme::drakeme() makes sure your project has a DESCRIPTION file, and if you have devtools installed, devtools::load_all() would just work (you may need to restart RStudio for the keyboard shortcut to work). By placing 0_packages.R within R directory, packages will also be loaded/attached.

  • A bookdown-based report/book in the flow: flowme::drakeme() sets the stage for the project to produce a report with bookdown. You simply add Rmd files to the “report” folder and you are good to go. This is achieved by including a target at the end of the plan to render all Rmd files in the report directory into a single book. Thus, you do not have to include one target for each Rmd, but rather just work on your Rmd and put them all in the report directory. Take a look at plan_bookme() and bookme() to see how this is done.

Here’s the file structure flowme::drakeme() includes in your current project:

+-- .gitignore
+-- .Rbuildignore
+-- DESCRIPTION
+-- R
|   +-- 0_packages.R
|   +-- drakeme.R
|   +-- plan_bookme.R
|   \-- plan_sessioninfo.R
+-- report
|   +-- chapter1.Rmd
|   +-- _bookdown.yml
|   +-- _output.yml
|   \-- _style.docx
\-- _drake.R

Workflow notes

  • The big picture plan (the_plan) should be defined in _drake.R, by binding together sub-plans. So no details on the processing here (unless it is a really simple project, in which case you probably do not need drake anyway, so, please just don’t). Hence, the plan should look something like the example below, which makes it easy for a newcomer to quickly know what the project is all about.

    the_plan <- drake::bind_plans(
    
      plan_network_analysis(),
      plan_survey_analysis(),
      plan_financial_analysis(),
      plan_bookme() # Just render the report using bookdown
    )
  • Define sub-plans within functions that return a drake::drake_plan. Defining the plans within functions instead of directly as objects helps navigating the project. You look at the plan, put the cursor on the sub-plan you want to go to and hit F2.

  • Include Rmd in the report directory, using the targets in the plans by calling drake::loadd or drake::readd