knitr::opts_chunk$set(
  cache = TRUE,
  collapse = TRUE,
  comment = "",
  echo = FALSE,
  fig.path = "man/figures/README-",
  out.width = "100%"
)
# The code that uses fs is hidden to keep instructions short
library(fs)
library(pactaCore)

pactaCore

Lifecycle: experimental R-CMD-check

The goal of pactaCore is run the core steps of the PACTA methodology with a single command, in a reproducible way.

System requirements

Docker.

Installation

You can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("2DegreesInvesting/pactaCore")

Setup

A good setup for a pacta project looks like this:

pacta <- path_home("pacta_tmp")
example_inputs <- dir_ls(
  system.file("extdata", package = "pactaCore"),
  regexp = "Input"
)
pactaCore:::create_pacta(pacta, input_paths = example)

dir_tree(pacta, all = TRUE)
#> path/to/private/pacta-data/
#> ├── ...
#> ...
env <- path(pacta, ".env")
writeLines(readLines(env))
# From the terminal
git clone git@github.com:2DegreesInvesting/pacta-data.git

Usage

Use the pactaCore package with library() and run_pacta() with your environment file.

library(pactaCore)

run_pacta(env = "~/pacta_tmp/.env")

The output/ directory is now populated with results:

dir_tree(pacta)

For each corresponding <pair-name>, the portfolio and parameter files must be named <pair-name>_Input.csv and <pair-name>_Input_PortfolioParameters.yml, respectively. For example:

  • This pair is valid: a_Input.csv, a_Input_PortfolioParameters.yml.

  • This pair is invalid: a_Input.csv, b_Input_PortfolioParameters.yml.

In the parameter files, whatever values you give to portfolio_name_in and investor_name_in will populate the columns portfolio_name and investor_name of some output files. For example:

  • A parameter file:
writeLines(readLines(example_inputs[[2]]))
  • A few rows of some relevant output files and columns:
paths <- fs::dir_ls(pactaCore:::results_path(pacta))
datasets <- lapply(paths, readRDS)
lapply(datasets, function(x) head(x[c("portfolio_name", "investor_name")]))

dir_delete(pacta)


2DegreesInvesting/pactaCore documentation built on Feb. 25, 2024, 3:20 a.m.