Skip to content

Commit

Permalink
clean code and refresh build
Browse files Browse the repository at this point in the history
  • Loading branch information
evaaepelde committed Jan 30, 2024
1 parent 318e287 commit 0744a5a
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 117 deletions.
68 changes: 52 additions & 16 deletions R/main.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# ex_shocks
#' ex_shocks
#'
#' Details: function to save a csv file in which the change in prices must be introduced to apply a price shock. Save the file, introduce the price shocks and load in R.The COICOP variables of the file correspond to the aggregate variables of the package, if you are not going to aggregate the COICOP variables you have to replace the column labels by the COICOP variables that appear in your dataset.
#' @return description
#' Function to save a csv file in which the change in prices must be
#' introduced to apply a price shock. Save the file, introduce the price shocks
#' and load in R.The COICOP variables of the file correspond to the aggregate
#' variables of the package, if you are not going to aggregate the COICOP
#' variables you have to replace the column labels by the COICOP variables that
#' appear in your dataset.
#' @return a csv file in which the change in prices must be introduced to apply a price shock
#' @export
ex_shocks <- function(){
exshock <- get("shocks")
Expand All @@ -10,17 +15,43 @@ ex_shocks <- function(){

#' calc_di
#'
#' Main function to calculate the distributional impacts for different price shocks and to save the results and the figures.
#' Main function to calculate the distributional impacts for different price shocks
#' and to save the results and the figures.
#' @param year year for the simulation. Available time series: 2006-2021.
#' @param elevate if TRUE elevate the HBS to national accounting. If FALSE (by default) do not elevate.
#' @param shocks a dataset with the price shocks per coicop to be applied. The format of the dataset has to correspond to the predefined one in the package. To save a csv file with the right format to enter the price shocks run `ex_shocks()`. You can enter more scenarios by including more columns to the right (e.g. s3). A price shock greater than 1 indicates a price increase (e.g. 1.1 indicates a 10% increase) and less than 1 indicates a price decrease (e.g. 0.9 indicates a 10% decrease).
#' @param var_impact variable(s) according to which you want to calculate distributional impacts. If "all" (by default) calculates the distributional impacts for each of the variables specified in the package. If not, you can indicate the variable on the basis of which you want to calculate the distributional impacts. If not, you can indicate a variable or a vector of variables to calculate distributional impacts.If you want to see the variables for which the calculation is available run `available_var_impact()`. If you do not want to calculate distributional impacts per variable indicate NULL.
#' @param var_intersec set of variables (2) according to which you want to calculate the intersectional distributional impacts. If "all", it calculates the distributional impacts for each of the combinations of variables specified in the package. If not, you can indicate the set of variables according to which you want to calculate the intersectional distributional impacts. If you wish to see the set of variables for which the calculation is available, run `available_var_intersec()`. To enter a set of variables for the calculation, it must follow the same format as the output of `available_var_intersec()`, i.e. a table whose columns have category_a and category_b as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default).
#' @param save if TRUE saves the dataframes with the results for the distributional impacts calculated by the function. If FALSE do not save.
#' @param file_name_impact name of the file to save the results of basic distributional impacts, if save TRUE. By default "D_impacts".
#' @param file_name_intersec name of the file to save the results of the intersectional distributional impacts, if save TRUE. By default "DI_impacts".
#' @param fig if TRUE (by default) create and save the figures of the distributional impacts calculated by the function. If FALSE do not create neither save.
#' @return a list containing the generated datasets summarising the basic or/and the intersectional distributional impacts per selected variable or set of variables.
#' @param shocks a dataset with the price shocks per coicop to be applied.
#' The format of the dataset has to correspond to the predefined one in the package.
#' To save a csv file with the right format to enter the price shocks run `ex_shocks()`.
#' You can enter more scenarios by including more columns to the right (e.g. s3).
#' A price shock greater than 1 indicates a price increase
#' (e.g. 1.1 indicates a 10\% increase) and less than 1 indicates a price decrease
#' (e.g. 0.9 indicates a 10\% decrease).
#' @param var_impact variable(s) according to which you want to calculate distributional
#' impacts. If "all" (by default) calculates the distributional impacts for each of the
#' variables specified in the package. If not, you can indicate the variable on the basis
#' of which you want to calculate the distributional impacts. If not, you can indicate a
#' variable or a vector of variables to calculate distributional impacts.If you want to
#' see the variables for which the calculation is available run `available_var_impact()`.
#' If you do not want to calculate distributional impacts per variable indicate `NULL`.
#' @param var_intersec set of variables (2) according to which you want to calculate
#' the intersectional distributional impacts. If "all", it calculates the distributional
#' impacts for each of the combinations of variables specified in the package. If not,
#' you can indicate the set of variables according to which you want to calculate the
#' intersectional distributional impacts. If you wish to see the set of variables for
#' which the calculation is available, run `available_var_intersec()`. To enter a set
#' of variables for the calculation, it must follow the same format as the output of
#' `available_var_intersec()`, i.e. a table whose columns have category_a and category_b
#' as their titles. If you do not want to calculate distributional impacts, indicate NULL (by default).
#' @param save if TRUE saves the dataframes with the results for the distributional
#' impacts calculated by the function. If FALSE do not save.
#' @param file_name_impact name of the file to save the results of basic distributional
#' impacts, if save TRUE. By default "D_impacts".
#' @param file_name_intersec name of the file to save the results of the intersectional
#' distributional impacts, if save TRUE. By default "DI_impacts".
#' @param fig if TRUE (by default) create and save the figures of the distributional
#' impacts calculated by the function. If FALSE do not create neither save.
#' @return a list containing the generated datasets summarising the basic or/and the
#' intersectional distributional impacts per selected variable or set of variables.
#' @export
calc_di <-function(year, elevate=F, shocks, var_impact = "all", var_intersec = NULL, save=T,
file_name_impact = "D_impact", file_name_intersec = "DI_impact", fig=T) {
Expand Down Expand Up @@ -83,18 +114,23 @@ calc_di <-function(year, elevate=F, shocks, var_impact = "all", var_intersec = N
return(return_list)
}

# available_var_impact
#' available_var_impact
#'
#' Details: function that returns the variables for which the calculation of basic distributional impacts is available.
#' Function that returns the variables for which the calculation of
#' basic distributional impacts is available.
#' @return variables for which the calculation of basic distributional impacts is available
#' @export
available_var_impact <- function(){
av_var_impact <- categories$categories
print(av_var_impact)
}

# available_var_intersec
#' available_var_intersec
#'
#' Details: function that returns the variables for which the calculation of intersectional distributional impacts is available.
#' Function that returns the set of variables for which the calculation
#' of intersectional distributional impacts is available.
#' @return set of variables for which the calculation of intersectional
#' distributional impacts is available
#' @export
available_var_intersec <- function(){
av_var_intersec <- is_categories
Expand Down
Loading

0 comments on commit 0744a5a

Please sign in to comment.