knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
) 

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

drakepkg

Cascadia R Conference 2019 Update: the slides from Tiernan Martin's talk can be downloaded here: drakepkg-slides-cascadiarconf2019.pdf


The goal of drakepkg is to demonstrate how a drake workflow can be organized as an R package.

Why do this? Because the package system in R provides a widely-adopted method of structuring, documenting, testing, and sharing R code. While most R packages are general purpose, this approach applies the same framework to a specific workflow (or set of workflows). It increases the reproducibility of a complex workflow without requiring users to recreate the workflow's environment with a container image (although that approach is compatible with drakepkg - see januz/drakepkg).

The drakepkg package is experimental in nature and currently requires some inconvenient steps (see the drake manual - 7.1.4 Workflows as R packages); please use caution when applying this approach to your own work.

Installation

You can install the released version of drakepkg from its Github repository with:

``` {r install, eval=FALSE} devtools::install_packages("tiernanmartin/drakepkg")

## Usage

The following table shows how each feature of a [`drake`](https://ropensci.github.io/drake/) workflow is made accessible within an R package: 

| `drake`                   | R Package                                                    |
|:------------------------- |:---------------------------------------------------------- |
| plans, commands           | functions (`R/*.R`)                                        |
| targets                   | stored in the cache (`.drake/`)                            |
| input files, output files | internal data (`inst/intdata/*`), external data (`inst/extdata/*`), images and documents (`inst/documents/*`)                           |


The package comes with two example [`drake`](https://ropensci.github.io/drake/) plans, both of which are loosely based on the `main` example included in the [`drake`](https://ropensci.github.io/drake/) package:

  1. An introductory plan: `drakepkg::get_example_plan_simple()`
  2. A plan that involves downloading external data: `drakepkg::get_example_plan_external()`

The first plan looks like this:

```r
library(drakepkg)
get_example_plan_simple()

Several commands used in the plan (e.g,create_plot(), write_report_simple()) are included as part of the drakepkg R package and so is the plan itself; the documentation for each of these functions can be accessed using R's help() function (for example, help(get_example_plan_simple)).

Once you have installed and loaded drakepkg, you can reproduce the introductory plan's workflow by performing the following steps:

  1. Copy the package's directories and source code files into your working directory with the copy_drakepkg_files() function
  2. View the plan (get_example_plan_simple()) and then make it (make(get_example_plan_simple()))
  3. Access the plan's targets using drake functions like readd() or loadd()
  4. View the html documents created by the workflow in the documents/ directory
# Step 1: copy the source code files into the working directory

copy_drakepkg_files()
# Step 2A: view the example plan

get_example_plan_simple()
# Step 2B: make the example plan

make(get_example_plan_simple())
# Step 3: examine the plan's targets

readd(fit)

readd(hist)

This example and others are available in the package vignette (vignette('drakepkg')).



tiernanmartin/drakepkg documentation built on March 11, 2020, 3:11 a.m.