knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(PFUWorkflow)

Introduction

PFUWorkflow is an R package that provides functions to build a database of primary-to-final-to-useful (PFU) energy conversion chain (ECC) societal exergy analyses (SEA). PFUWorkflow makes use of the drake package. PFUWorkflow creates drake workflows that ensure that "What gets done stays done," leading to analyses that are more reproducible and less prone to errors.

Quick start

To get started, follow these steps:

  1. Create a new R project in a new folder or repository.
  2. Make an R directory inside the new folder.
  3. Inside the R directory, make a file called plan.R that calls PFUWorkflow::get_plan() like this:
plan <- PFUWorkflow::get_plan(countries = c("GHA", "ZAF"), 
                              max_year = 2017,
                              iea_data_path = "<<IEA extended energy balance path>>", 
                              country_concordance_path = "<<Country concordance path>>",
                              phi_constants_path = "<<phi constants path>>", 
                              ceda_data_folder = "<<CEDA temperature data path>>",
                              machine_data_path = "<<Machine data path>>",
                              exemplar_table_path = "<<exemplar table path>>",
                              fu_analysis_folder = "<<FU analysis folder>>", 
                              reports_source_folders = "<<Reports source folders>>",
                              reports_dest_folder = "<<Reports output folder>>",
                              pipeline_caches_folder = "<<Pipeline caches folder>>",
                              pipeline_releases_folder = "<<Pipeline releases folder>>",
                              release = FALSE)

where

The plan object is a data frame that provides a list of "targets" and code that will generate the target, in the order the targets will be completed.

plan
  1. To visualize all dependencies in the plan,
drake::vis_drake_graph(plan)
  1. To execute the plan, call `drake::make(plan) or drake::r_make(plan). When drake is installed, the Addins menu contains the item Run a drake workflow, which sources the plan.R file and calls drake::r_make(plan).

Targets

A list of targets can be found with PFUWorkflow::target_names. The meanings of the targets can be obtained with ?PFUWorkflow::target_names.

Results

To query the results of executing the plan, say drake::readd(<<target>>), where <<target>> is unquoted. Alternatively, drake::readd("<<target>>", character_only = TRUE) for a string <<target>>.

Targets are computed by country. Say PFUWorkflow::readd_by_country("<<target>>", "<<country>>") to obtain the value of a target for a country or vector of countries. Both <<target>> and <<country>> need to be strings (enclosed in "") for PFUWorkflow::readd_by_country().

unlink(".drake", recursive=TRUE)


MatthewHeun/SEAPSUTWorkflow documentation built on April 22, 2022, 2:21 p.m.