PFUWorkflow
PFUWorkflow.Rmd
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:
- Create a new
Rproject in a new folder or repository. - Make an
Rdirectory inside the new folder. - Inside the
Rdirectory, make a file calledplan.Rthat callsPFUWorkflow::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
-
countriesis the list of countries to be analyzed, -
max_yearis the latest year to be analyzed, -
<<IEA extended energy balance path>>is the path to a.csvfile that contains IEA extended energy balance data, -
<<phi constants path>>is the path to an Excel file of constant values of phi (the exergy-to-energy ratio), -
<<CEDA temperature data path>>is the path to CEDA cru_cy temperature data downloaded throughCEDATools, -
<<Machine data path>>is the path to the Machine data excel files containing Eta.fu, Phi.u, and other data. -
<<exemplar table path>>is the path to an exemplar table (see below), -
<<FU analysis folder>>is the path to a folder containing final-to-useful analyses, -
<<Reports source folders>>is a vector of paths to folders containing report sources (usually.Rmdand.Rnwfiles), -
<<Reports output folder>>is the path to a folder for completed reports, -
<<Pipeline caches folder>>is the path to a folder in which the pipeline cache is stored as a .zip file, and -
<<Pipeline releases folder>>is the path to a folder in which releases of pipeline objects are stored.
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
#> # A tibble: 51 × 3
#> target command dynamic
#> <chr> <expr_lst> <expr_lst>
#> 1 countries c(c("GHA", "ZAF")) NA
#> 2 alloc_and_eff_couns unique(c(countries, NULL)) NA
#> 3 max_year 2017 NA
#> 4 iea_data_path "<<IEA extended energy balance path>>" NA
#> 5 country_concordance_path "<<Country concordance path>>" NA
#> 6 phi_constants_path "<<phi constants path>>" NA
#> 7 ceda_data_folder "<<CEDA temperature data path>>" NA
#> 8 machine_data_path "<<Machine data path>>" NA
#> 9 exemplar_table_path "<<exemplar table path>>" NA
#> 10 fu_analysis_folder "<<FU analysis folder>>" NA
#> # … with 41 more rows- To visualize all dependencies in the plan,
drake::vis_drake_graph(plan)- To execute the plan, call `
drake::make(plan)ordrake::r_make(plan). Whendrakeis installed, theAddinsmenu contains the itemRun a drake workflow,which sources theplan.Rfile and callsdrake::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().