|
#' External sector and macroeconomic indicators: aggregate output |
|
#' |
|
#' @param year Scalar integer |
|
#' @param metric One of "gdp", "gni" |
|
#' @param output_by One of "expenditure", "activity" |
|
#' @export |
|
#' @return nested list with "amt" and "change". Different base rates are |
|
#' nested within. |
|
#' @examples |
|
#' # we retrieve GDP by expenditure by default |
|
#' res <- get_aggregate_output() |
|
#' |
|
#' # result is a nested list |
|
#' str(res) |
|
#' |
|
#' # to get change at 2000 prices run the following: |
|
#' res$change$base_2000 |
|
#' @name msb3_output |
|
get_aggregate_output <- function(year = NULL, metric = "gdp", output_by = "expenditure", change = TRUE) { |
|
assert_that(metric %in% c("gdp", "gni")) |
|
assert_that(output_by %in% c("expenditure", "activity")) |
|
if (metric == "gdp") { |
|
if (output_by == "expenditure") { |
|
message("GDP by expenditure") |
|
return( |
|
list( |
|
# TODO find a better name than amt |
|
# amt = .get_msb_data("3.2", year = year), |
|
change = list( |
|
base_2000 = .get_msb_data("3.3a", year = year), |
|
base_2010 = .get_msb_data("3.3", year = year) |
|
) |
|
) |
|
) |
|
} else if (output_by == "activity") { |
|
return( |
|
list( |
|
amt = list( |
|
base_2000 = .get_msb_data("3.4.1a", year = year), |
|
base_2010 = .get_msb_data("3.4.1", year = year), |
|
current = .get_msb_data("3.4.2", year = year) |
|
), |
|
change = list( |
|
base_2000 = .get_msb_data("3.4a", year = year), |
|
base_2010 = .get_msb_data("3.4", year = year) |
|
) |
|
) |
|
) |
|
} |
|
} else if (metric == "gni") { |
|
if (output_by == "expenditure") { |
|
return( |
|
list( |
|
# TODO find a better name than amt |
|
# amt = .get_msb_data("3.2", year = year), |
|
amt = list( |
|
base_2000 = .get_msb_data("3.3.1a", year = year), |
|
base_2010 = .get_msb_data("3.3.1", year = year) |
|
), |
|
change = NULL |
|
) |
|
) |
|
} else { |
|
message("No endpoint for retrieving GNI by economic activity") |
|
NULL |
|
} |
|
} |
|
|
|
} |