Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions R/compute_fgt_new.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OLD APPROACH WITH MEAN --------------

# Efficient FGT calculation for a data.table and vector of poverty lines
#' Title
#' Efficient FGT calculation for a data.table and vector of poverty lines
#'
#'
#' @param dt data frame with `welfare` and `weight` columns
#' @param welfare character: welfare variable name
Expand Down Expand Up @@ -76,8 +76,6 @@ compute_fgt_dt <- function(dt, welfare, weight, povlines, mean_and_med = FALSE)

}



#' Efficient FGT calculation for vectors (No data.table)
#'
#' @param w character: welfare variable name
Expand Down Expand Up @@ -125,7 +123,6 @@ compute_fgt <- function(w, wt, povlines) {
}
}


data.table(
povline = povlines,
headcount = res[, 1],
Expand Down Expand Up @@ -166,8 +163,6 @@ DT_fgt_by_rl <- \(x, y, nx, povline) {
)]
}



#' jkoin reporting level and lt list into one data.table
#'
#' @rdname map_fgt
Expand Down Expand Up @@ -196,11 +191,10 @@ map_lt_to_dt <- \(lt, l_rl_rows, povline) {
rbindlist(fill = TRUE)
}


#' map over list of data.tables and indices to compute FGT by reporting_level
#'
#' @param lt list of data.tables with welfare and weight data
#' @param l_rl_rows list of indeces
#' @param l_rl_rows list of indices
#'
#' @return data.table with all measured
#' @keywords internal
Expand Down Expand Up @@ -273,8 +267,6 @@ load_data_list <- \(metadata) {

}



pov_from_DT <- function(DT, povline, g, cores = 1) {
w <- DT$welfare
wt <- DT$weight
Expand Down Expand Up @@ -322,10 +314,6 @@ pov_from_DT <- function(DT, povline, g, cores = 1) {
out
}





# pov_from_DT2 <- function(DT, povline, g) {
# fgt0 <- numeric(length(povline))
# fgt1 <- numeric(length(povline))
Expand Down
17 changes: 6 additions & 11 deletions R/duckdb_func.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @inheritParams subset_lkup
#'
#' @return Dataframe
#' @return list with 3 elements data_present_in_master, modified `lkup` value and `povline`
#' @export
return_if_exists <- function(slkup,
povline,
Expand Down Expand Up @@ -200,7 +200,7 @@ return_if_exists <- function(slkup,
#' @param dat Dataframe to be appended
#' @param cache_file_path path where cache file is saved
#'
#' @return number of rows updated
#' @return a number i.e no. of rows updated
#' @export
#'
update_master_file <- function(dat,
Expand Down Expand Up @@ -291,7 +291,7 @@ update_master_file <- function(dat,
"))

duckdb::dbDisconnect(write_con)

if (nr > 0 && verbose) message(glue("{target_file} is updated."))

return(nr)
Expand Down Expand Up @@ -362,7 +362,7 @@ reset_cache <- function(pass = Sys.getenv('PIP_CACHE_LOCAL_KEY'),
DBI::dbExecute(write_con, "DELETE from fg_master_file")
}
duckdb::dbDisconnect(write_con)

}

create_duckdb_file <- function(cache_file_path) {
Expand All @@ -388,17 +388,14 @@ create_duckdb_file <- function(cache_file_path) {
watts DOUBLE
)")
DBI::dbDisconnect(con)

}



}

#' Load Intermediate cache data
#'
#' @inheritParams return_if_exists
#'
#' @return data frame
#' @return cached data frame
#' @export
load_inter_cache <- function(lkup = NULL,
cache_file_path = NULL,
Expand All @@ -423,8 +420,6 @@ load_inter_cache <- function(lkup = NULL,
# connection object if it is not closed More details here
# https://app.clickup.com/t/868cdpe3q
duckdb::dbDisconnect(con)


setDT(master_file)
}

11 changes: 0 additions & 11 deletions R/fg_pip.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ fg_pip <- function(country,

}


#' Remove duplicated rows created during the interpolation process
#'
#' @param df data.table: Table of results created in `fg_pip()`
Expand Down Expand Up @@ -239,8 +238,6 @@ fg_remove_duplicates <- function(df,
# Ensure that out does not have duplicates
df <- unique(df)
}


return(df)
}

Expand Down Expand Up @@ -277,11 +274,6 @@ fg_assign_nas_values_to_dup_cols <- function(df,
return(df)
}






#' Create full list for fg data load, not including country-years in cache
#'
#' @param metadata data table from subset_lkup()$lkup
Expand All @@ -292,6 +284,3 @@ create_full_list <- function(metadata) {
funique()

}



9 changes: 0 additions & 9 deletions R/pip.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#' Compute PIP statistics
#'
#' Compute the main PIP poverty and inequality statistics.
Expand Down Expand Up @@ -97,10 +95,3 @@ pip <- function(country = "ALL",
out

}







12 changes: 0 additions & 12 deletions R/pip_grp_logic.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#' @rdname pip_agg
#'
#' @return data.table
#' @examples
#' \dontrun{
#' # Create lkups
#' }
#' @export
pip_grp_logic <- function(country = "ALL",
year = "ALL",
Expand Down Expand Up @@ -243,20 +239,14 @@ pip_grp_logic <- function(country = "ALL",
} else {
ret <- de
}


# add new estimate type

ret <- estimate_type_var(ret,lkup)


# Censor regional values ----------- We are not censoring at this stage
# anymore because we need to show al the years in the homre page, including
# nowcast. we are now filtering at the UI and wrappers levels
# if (censor) {
# ret <- censor_rows(ret, lkup[["censored"]], type = "regions")
# }

data.table::setcolorder(ret, names_grp)

# Select columns
Expand All @@ -266,8 +256,6 @@ pip_grp_logic <- function(country = "ALL",

#Order rows by country code and reporting year
setorder(ret, region_code , reporting_year)


# ____________________________________________________________________
# Return ####
return(ret)
Expand Down
8 changes: 2 additions & 6 deletions R/rg_pip.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Compute the main PIP poverty and inequality statistics for survey years.
#'
#' @inheritParams pip
#' @return data.frame
#' @return list of 2 data.frames, main_data and data_in_cache
#' @keywords internal
rg_pip <- function(country,
year,
Expand Down Expand Up @@ -78,7 +78,7 @@ rg_pip <- function(country,
res <- lapply(lt, process_dt, povline = povline)
}
rm(lt)


res <- rbindlist(res, fill = TRUE)

Expand All @@ -100,9 +100,5 @@ rg_pip <- function(country,

setnames(out, "povline", "poverty_line")


return(list(main_data = out, data_in_cache = data_present_in_master))
}



Loading