Skip to content

Commit

Permalink
Fix/48 remove globalenv (#49)
Browse files Browse the repository at this point in the history
Closes #48

---------

Co-authored-by: CJ Yetman <[email protected]>
  • Loading branch information
AlexAxthelm and cjyetman authored May 28, 2024
1 parent 384e220 commit 59dedef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
22 changes: 17 additions & 5 deletions R/get_abcd_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions R/merge_in_geography.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion man/get_abcd_raw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/merge_in_geography.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 59dedef

Please sign in to comment.