From 59dedefb73ab1ec575cfc9a70e0cfd9b6da6bdc4 Mon Sep 17 00:00:00 2001 From: Alex Axthelm Date: Tue, 28 May 2024 12:08:53 +0200 Subject: [PATCH] Fix/48 remove globalenv (#49) Closes #48 --------- Co-authored-by: CJ Yetman --- R/get_abcd_raw.R | 22 +++++++++++++++++----- R/merge_in_geography.R | 10 ++++++++-- man/get_abcd_raw.Rd | 18 +++++++++++++++++- man/merge_in_geography.Rd | 5 ++++- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/R/get_abcd_raw.R b/R/get_abcd_raw.R index a996aae..5d98d77 100644 --- a/R/get_abcd_raw.R +++ b/R/get_abcd_raw.R @@ -3,26 +3,38 @@ #' A longer description of the function #' #' @param portfolio_type A description of the argument +#' @param analysis_inputs_path Path to directory containing ABCD Data files +#' @param start_year Start year of the analysis +#' @param time_horizon Length of the analysis in years (analysis will run from +#' `start_year` to `start_year + time_horizon`) +#' @param sector_list (character) A vector of PACTA sectors to include in the +#' analysis. #' #' @return A description of the return value #' #' @export -get_abcd_raw <- function(portfolio_type) { +get_abcd_raw <- function( + portfolio_type, + analysis_inputs_path, + start_year, + time_horizon, + sector_list +) { filename_eq_raw <- "masterdata_ownership_datastore.rds" filename_cb_raw <- "masterdata_debt_datastore.rds" if (portfolio_type == "Equity") { - abcd_raw <- readr::read_rds(file.path(.GlobalEnv$analysis_inputs_path, filename_eq_raw)) + abcd_raw <- readr::read_rds(file.path(analysis_inputs_path, filename_eq_raw)) } if (portfolio_type == "Bonds") { - abcd_raw <- readr::read_rds(file.path(.GlobalEnv$analysis_inputs_path, filename_cb_raw)) + abcd_raw <- readr::read_rds(file.path(analysis_inputs_path, filename_cb_raw)) } abcd_raw <- abcd_raw %>% - filter(.data$year %in% seq(.GlobalEnv$start_year, .GlobalEnv$start_year + .GlobalEnv$time_horizon)) %>% - filter(.data$ald_sector %in% .GlobalEnv$sector_list) %>% + filter(.data$year %in% seq(start_year, start_year + time_horizon)) %>% + filter(.data$ald_sector %in% sector_list) %>% mutate( ald_sector = if_else( .data$technology == "Coal", diff --git a/R/merge_in_geography.R b/R/merge_in_geography.R index ed70538..a1f9509 100644 --- a/R/merge_in_geography.R +++ b/R/merge_in_geography.R @@ -4,12 +4,18 @@ #' #' @param portfolio A description of the argument #' @param ald_raw A description of the argument +#' @param sector_list (character) A vector of PACTA sectors to include in the +#' analysis. #' #' @return A description of the return value #' #' @export -merge_in_geography <- function(portfolio, ald_raw) { +merge_in_geography <- function( + portfolio, + ald_raw, + sector_list +) { company_all <- portfolio %>% distinct( .data$allocation, @@ -20,7 +26,7 @@ merge_in_geography <- function(portfolio, ald_raw) { company_all <- company_all %>% - filter(.data$financial_sector %in% .GlobalEnv$sector_list) + filter(.data$financial_sector %in% sector_list) ### join with MASTER to get country production company_all_data <- left_join( diff --git a/man/get_abcd_raw.Rd b/man/get_abcd_raw.Rd index 6e57043..a82f1c4 100644 --- a/man/get_abcd_raw.Rd +++ b/man/get_abcd_raw.Rd @@ -4,10 +4,26 @@ \alias{get_abcd_raw} \title{A short description of the function} \usage{ -get_abcd_raw(portfolio_type) +get_abcd_raw( + portfolio_type, + analysis_inputs_path, + start_year, + time_horizon, + sector_list +) } \arguments{ \item{portfolio_type}{A description of the argument} + +\item{analysis_inputs_path}{Path to directory containing ABCD Data files} + +\item{start_year}{Start year of the analysis} + +\item{time_horizon}{Length of the analysis in years (analysis will run from +\code{start_year} to \code{start_year + time_horizon})} + +\item{sector_list}{(character) A vector of PACTA sectors to include in the +analysis.} } \value{ A description of the return value diff --git a/man/merge_in_geography.Rd b/man/merge_in_geography.Rd index bbfb3d4..df795a8 100644 --- a/man/merge_in_geography.Rd +++ b/man/merge_in_geography.Rd @@ -4,12 +4,15 @@ \alias{merge_in_geography} \title{A short description of the function} \usage{ -merge_in_geography(portfolio, ald_raw) +merge_in_geography(portfolio, ald_raw, sector_list) } \arguments{ \item{portfolio}{A description of the argument} \item{ald_raw}{A description of the argument} + +\item{sector_list}{(character) A vector of PACTA sectors to include in the +analysis.} } \value{ A description of the return value