From e9ffd729480bd031b29fcfb7775ab6648b4b6ef5 Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 09:44:32 -0400 Subject: [PATCH 1/9] fix title and description in DESCRIPTION --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 79b3146..8ddf607 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: pipr -Title: Client for the PIP API +Title: Client for the Poverty and Inequality Platform ('PIP') API Version: 1.0.0 Authors@R: c(person(given = "Tony", @@ -14,14 +14,14 @@ Authors@R: family = "Shah", role = "aut", email = "shahronak47@yahoo.in"), - person(given = "R. Andrés", + person(given = "R.Andrés", family = "Castañeda", role = "aut", email = "acastanedaa@worldbank.org"), person(given = "World Bank", role = "cph") ) -Description: Provides an interface to compute poverty and inequality +Description: An interface to compute poverty and inequality indicators for more than 160 countries and regions from the World Bank's database of household surveys. License: MIT + file LICENSE From 575c3f884a8a42be6969a22cac04c48f5fd9c159 Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 09:53:08 -0400 Subject: [PATCH 2/9] Add API url with angle brakets --- DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8ddf607..a577330 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,8 +29,9 @@ Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -URL: https://github.com/worldbank/pipr, - https://worldbank.github.io/pipr/ +URL: https://worldbank.github.io/pipr/, + https://github.com/worldbank/pipr, + BugReports: https://github.com/worldbank/pipr/issues Suggests: covr, From cd36991423050430311d895ae8551b9678da948e Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 10:28:20 -0400 Subject: [PATCH 3/9] add information about the pip_api class --- R/aaa.R | 9 ++------- R/get_aux.R | 4 ++-- R/utils.R | 7 ++++++- man/parse_response.Rd | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 man/parse_response.Rd diff --git a/R/aaa.R b/R/aaa.R index 88535e8..84d15a3 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -28,10 +28,7 @@ set_aux <- function(table, if (to_set == 2) { msg <- c("Setting {.field {table}} into {.code .pip} aborted") - cli::cli_abort(msg, - class = "stamp_error", - wrap = TRUE - ) + cli::cli_abort(msg, wrap = TRUE) } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -122,9 +119,7 @@ call_aux <- function(table = NULL) { return(rlang::env_get(.pip, table)) } else { msg <- c("*" = "Table {.field {table}} does not exist") - cli::cli_abort(msg, - class = "pipr_error", - wrap = TRUE) + cli::cli_abort(msg, wrap = TRUE) } } diff --git a/R/get_aux.R b/R/get_aux.R index 8dfc363..2bcd92f 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -95,7 +95,7 @@ get_aux <- function(table = NULL, } else { msg <- c("Invalid sintax in {.field assign_tb}", "*" = "{.field assign_tb} must be logical or character.") - cli::cli_abort(msg, class = "pipr_error", wrap = TRUE) + cli::cli_abort(msg, wrap = TRUE) } srt <- set_aux(table = tb_name, @@ -116,7 +116,7 @@ get_aux <- function(table = NULL, } else { msg <- c("table {.strong {table}} could not be saved in env {.env .pip}") - cli::cli_abort(msg, class = "pipr_error", wrap = TRUE) + cli::cli_abort(msg, wrap = TRUE) } diff --git a/R/utils.R b/R/utils.R index 9e5f181..6df7e68 100644 --- a/R/utils.R +++ b/R/utils.R @@ -101,10 +101,15 @@ build_args <- function(.country = NULL, return(args) } + #' parse_response #' @param res A httr response #' @inheritParams get_stats -#' @noRd +#' +#' @return If `simplify = TRUE`, it returns a tibble with the requested content. +#' If `simplify = FALSE`, it returns a list of class "pip_api" with +#' information about the PIP API query +#' @keywords internal parse_response <- function(res, simplify) { # Get response type diff --git a/man/parse_response.Rd b/man/parse_response.Rd new file mode 100644 index 0000000..2902dd0 --- /dev/null +++ b/man/parse_response.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{parse_response} +\alias{parse_response} +\title{parse_response} +\usage{ +parse_response(res, simplify) +} +\arguments{ +\item{res}{A httr response} + +\item{simplify}{logical: If TRUE (the default) the response is returned as a +\code{tibble}} +} +\value{ +If \code{simplify = TRUE}, it returns a tibble with the requested content. +If \code{simplify = FALSE}, it returns a list of class "pip_api" with +information about the PIP API query +} +\description{ +parse_response +} +\keyword{internal} From c05f3334d0063c9b0fec1d865b82a25304f19406 Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 10:50:21 -0400 Subject: [PATCH 4/9] delete Rd for aux specific functions and combine with get_aux --- NAMESPACE | 13 -- R/get_aux.R | 113 ++++++---------- man/get_aux.Rd | 240 +++++++++++++++++++++++++++++++++- man/get_countries.Rd | 38 ------ man/get_cpi.Rd | 39 ------ man/get_dictionary.Rd | 38 ------ man/get_gdp.Rd | 38 ------ man/get_hfce.Rd | 38 ------ man/get_incgrp_coverage.Rd | 39 ------ man/get_interpolated_means.Rd | 41 ------ man/get_pop.Rd | 38 ------ man/get_pop_region.Rd | 38 ------ man/get_ppp.Rd | 38 ------ man/get_region_coverage.Rd | 38 ------ man/get_regions.Rd | 38 ------ man/get_survey_means.Rd | 39 ------ 16 files changed, 276 insertions(+), 590 deletions(-) delete mode 100644 man/get_countries.Rd delete mode 100644 man/get_cpi.Rd delete mode 100644 man/get_dictionary.Rd delete mode 100644 man/get_gdp.Rd delete mode 100644 man/get_hfce.Rd delete mode 100644 man/get_incgrp_coverage.Rd delete mode 100644 man/get_interpolated_means.Rd delete mode 100644 man/get_pop.Rd delete mode 100644 man/get_pop_region.Rd delete mode 100644 man/get_ppp.Rd delete mode 100644 man/get_region_coverage.Rd delete mode 100644 man/get_regions.Rd delete mode 100644 man/get_survey_means.Rd diff --git a/NAMESPACE b/NAMESPACE index 9d2ad3a..9a730e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,20 +4,7 @@ export(call_aux) export(check_api) export(display_aux) export(get_aux) -export(get_countries) -export(get_cpi) -export(get_dictionary) -export(get_gdp) -export(get_hfce) -export(get_incgrp_coverage) -export(get_interpolated_means) export(get_pip_info) -export(get_pop) -export(get_pop_region) -export(get_ppp) -export(get_region_coverage) -export(get_regions) export(get_stats) -export(get_survey_means) export(get_versions) export(get_wb) diff --git a/R/get_aux.R b/R/get_aux.R index 2bcd92f..58f6bf7 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -1,7 +1,11 @@ #' Get auxiliary data #' -#' Get an auxiliary dataset. If no table is specified a vector with possible -#' inputs will be returned. +#' @description `get_aux()` Get an auxiliary dataset. If no table is specified a +#' vector with possible inputs will be returned. +#' +#' `get_countries()` Returns a table countries with their full names, ISO codes, +#' and associated region code +#' #' #' @param table Aux table #' @param assign_tb assigns table to specified name to the `.pip` environment. @@ -12,7 +16,8 @@ #' @param force logical: force replacement. Default is FALSE #' #' @return tibble or list. If `assign_tb` is TRUE or character, it will return -#' TRUE if data was assign properly to .pip env +#' TRUE if data was assign properly to .pip env. If `simplify = FALSE`, it +#' returns a list of class "pip_api" #' @export #' @examples #' \dontrun{ @@ -127,11 +132,8 @@ get_aux <- function(table = NULL, } -#' get_countries -#' @description Returns a table countries with their full names, ISO codes, and -#' associated region code -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table countries with their full names, ISO +#' codes, and associated region code #' @examples #' \dontrun{ #' # Short hand to get countries @@ -153,11 +155,8 @@ get_countries <- function(version = NULL, } -#' get_regions -#' @description Returns a table regional grouping used for computing aggregate -#' poverty statistics. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table regional grouping used for computing +#' aggregate poverty statistics. #' @examples #' \dontrun{ #' # Short hand to get regions @@ -179,12 +178,8 @@ get_regions <- function(version = NULL, } -#' get_cpi() -#' @description Returns a table of Consumer Price Index (CPI) values used for -#' poverty and inequality computations. -#' statistics -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of Consumer Price Index (CPI) values used +#' for poverty and inequality computations. statistics #' @examples #' \dontrun{ #' # Short hand to get cpi @@ -206,11 +201,8 @@ get_cpi <- function(version = NULL, } -#' get_dictionary -#' @description Returns a data dictionary with a description of all variables -#' available through the PIP API. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a data dictionary with a description of all +#' variables available through the PIP API. #' @examples #' \dontrun{ #' # Short hand to get dictionary @@ -232,11 +224,8 @@ get_dictionary <- function(version = NULL, } -#' get_gdp() -#' @description Returns a table of Growth Domestic Product (GDP) values used for -#' poverty and inequality statistics. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of Growth Domestic Product (GDP) values +#' used for poverty and inequality statistics. #' @examples #' \dontrun{ #' # Short hand to get gdp @@ -258,12 +247,9 @@ get_gdp <- function(version = NULL, } -#' get_incgrp_coverage -#' @description Returns a table of survey coverage for low and lower-middle -#' income countries. If this coverage is less than 50%, World level aggregate -#' statistics will not be computed. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of survey coverage for low and +#' lower-middle income countries. If this coverage is less than 50%, World +#' level aggregate statistics will not be computed. #' @examples #' \dontrun{ #' # Short hand to get incgrp_coverage @@ -285,14 +271,11 @@ get_incgrp_coverage <- function(version = NULL, } -#' get_interpolated_means -#' @description Returns a table of key information and statistics for all years -#' for which poverty and inequality statistics are either available (household -#' survey exists) or extra- / interpolated. -#' Please see \code{\link{get_dictionary}} for more information about -#' each variable available in this table. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of key information and statistics for all +#' years for which poverty and inequality statistics are either available +#' (household survey exists) or extra- / interpolated. Please see +#' \code{\link{get_dictionary}} for more information about each variable +#' available in this table. #' @examples #' \dontrun{ #' # Short hand to get interpolated_means @@ -313,12 +296,8 @@ get_interpolated_means <- function(version = NULL, ) } -#' get_hfce -#' -#' @description Returns a table of Household Final Consumption Expenditure (HFCE) values -#' used for poverty and inequality computations. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of Household Final Consumption +#' Expenditure (HFCE) values used for poverty and inequality computations. #' @examples #' \dontrun{ #' # Short hand to get hfce @@ -339,11 +318,8 @@ get_hfce <- function(version = NULL, ) } -#' get_pop -#' @description Returns a table of population values used for poverty and +#' @describeIn get_aux Returns a table of population values used for poverty and #' inequality computations. -#' @inheritParams get_aux -#' @export #' @examples #' \dontrun{ #' # Short hand to get pop @@ -364,11 +340,9 @@ get_pop <- function(version = NULL, ) } -#' get_pop_region -#' @description Returns a table of total population by region-year. These values -#' are used for the computation of regional aggregate poverty statistics. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of total population by region-year. These +#' values are used for the computation of regional aggregate poverty +#' statistics. #' @examples #' \dontrun{ #' # Short hand to get pop_region @@ -390,11 +364,8 @@ get_pop_region <- function(version = NULL, } -#' get_ppp -#' @description Returns a table of Purchasing Power Parity (PPP) values -#' used for poverty and inequality computations. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of Purchasing Power Parity (PPP) values +#' used for poverty and inequality computations. #' @examples #' \dontrun{ #' # Short hand to get ppp @@ -415,11 +386,8 @@ get_ppp <- function(version = NULL, ) } -#' get_region_coverage -#' @description Return a table of regional survey coverage: Percentage of -#' available surveys for a specific region-year. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Return a table of regional survey coverage: Percentage of +#' available surveys for a specific region-year. #' @examples #' \dontrun{ #' # Short hand to get region_coverage @@ -441,12 +409,9 @@ get_region_coverage <- function(version = NULL, } -#' get_survey_means -#' @description Returns a table of all available surveys and associated key -#' statistics. Please see \code{\link{get_dictionary}} for more information about -#' each variable available in this table. -#' @inheritParams get_aux -#' @export +#' @describeIn get_aux Returns a table of all available surveys and associated +#' key statistics. Please see \code{\link{get_dictionary}} for more +#' information about each variable available in this table. #' @examples #' \dontrun{ #' # Short hand to get survey_means diff --git a/man/get_aux.Rd b/man/get_aux.Rd index b7d1604..e1d8ebf 100644 --- a/man/get_aux.Rd +++ b/man/get_aux.Rd @@ -2,6 +2,19 @@ % Please edit documentation in R/get_aux.R \name{get_aux} \alias{get_aux} +\alias{get_countries} +\alias{get_regions} +\alias{get_cpi} +\alias{get_dictionary} +\alias{get_gdp} +\alias{get_incgrp_coverage} +\alias{get_interpolated_means} +\alias{get_hfce} +\alias{get_pop} +\alias{get_pop_region} +\alias{get_ppp} +\alias{get_region_coverage} +\alias{get_survey_means} \title{Get auxiliary data} \usage{ get_aux( @@ -16,6 +29,123 @@ get_aux( assign_tb = FALSE, force = FALSE ) + +get_countries( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_regions( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_cpi( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_dictionary( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_gdp( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_incgrp_coverage( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_interpolated_means( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_hfce( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_pop( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_pop_region( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_ppp( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_region_coverage( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) + +get_survey_means( + version = NULL, + ppp_version = NULL, + release_version = NULL, + api_version = "v1", + format = c("rds", "json", "csv"), + server = NULL +) } \arguments{ \item{table}{Aux table} @@ -44,12 +174,64 @@ character, the table will be assigned to that name.} } \value{ tibble or list. If \code{assign_tb} is TRUE or character, it will return -TRUE if data was assign properly to .pip env +TRUE if data was assign properly to .pip env. If \code{simplify = FALSE}, it +returns a list of class "pip_api" } \description{ -Get an auxiliary dataset. If no table is specified a vector with possible -inputs will be returned. +\code{get_aux()} Get an auxiliary dataset. If no table is specified a +vector with possible inputs will be returned. + +\code{get_countries()} Returns a table countries with their full names, ISO codes, +and associated region code } +\section{Functions}{ +\itemize{ +\item \code{get_countries()}: Returns a table countries with their full names, ISO +codes, and associated region code + +\item \code{get_regions()}: Returns a table regional grouping used for computing +aggregate poverty statistics. + +\item \code{get_cpi()}: Returns a table of Consumer Price Index (CPI) values used +for poverty and inequality computations. statistics + +\item \code{get_dictionary()}: Returns a data dictionary with a description of all +variables available through the PIP API. + +\item \code{get_gdp()}: Returns a table of Growth Domestic Product (GDP) values +used for poverty and inequality statistics. + +\item \code{get_incgrp_coverage()}: Returns a table of survey coverage for low and +lower-middle income countries. If this coverage is less than 50\%, World +level aggregate statistics will not be computed. + +\item \code{get_interpolated_means()}: Returns a table of key information and statistics for all +years for which poverty and inequality statistics are either available +(household survey exists) or extra- / interpolated. Please see +\code{\link{get_dictionary}} for more information about each variable +available in this table. + +\item \code{get_hfce()}: Returns a table of Household Final Consumption +Expenditure (HFCE) values used for poverty and inequality computations. + +\item \code{get_pop()}: Returns a table of population values used for poverty and +inequality computations. + +\item \code{get_pop_region()}: Returns a table of total population by region-year. These +values are used for the computation of regional aggregate poverty +statistics. + +\item \code{get_ppp()}: Returns a table of Purchasing Power Parity (PPP) values +used for poverty and inequality computations. + +\item \code{get_region_coverage()}: Return a table of regional survey coverage: Percentage of +available surveys for a specific region-year. + +\item \code{get_survey_means()}: Returns a table of all available surveys and associated +key statistics. Please see \code{\link{get_dictionary}} for more +information about each variable available in this table. + +}} \examples{ \dontrun{ # Get list of tables @@ -73,5 +255,57 @@ get_aux("gdp", assign_tb = TRUE) # Bind gdp table to "new_name" in .pip env get_aux("gdp", assign_tb = "new_name") +} +\dontrun{ +# Short hand to get countries +get_countries() +} +\dontrun{ +# Short hand to get regions +get_regions() +} +\dontrun{ +# Short hand to get cpi +get_cpi() +} +\dontrun{ +# Short hand to get dictionary +get_dictionary() +} +\dontrun{ +# Short hand to get gdp +get_gdp() +} +\dontrun{ +# Short hand to get incgrp_coverage +get_incgrp_coverage() +} +\dontrun{ +# Short hand to get interpolated_means +get_interpolated_means() +} +\dontrun{ +# Short hand to get hfce +get_hfce() +} +\dontrun{ +# Short hand to get pop +get_pop() +} +\dontrun{ +# Short hand to get pop_region +get_pop_region() +} +\dontrun{ +# Short hand to get ppp +get_ppp() +} +\dontrun{ +# Short hand to get region_coverage +get_region_coverage() +} +\dontrun{ +# Short hand to get survey_means +get_survey_means() } } diff --git a/man/get_countries.Rd b/man/get_countries.Rd deleted file mode 100644 index 0be4405..0000000 --- a/man/get_countries.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_countries} -\alias{get_countries} -\title{get_countries} -\usage{ -get_countries( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table countries with their full names, ISO codes, and -associated region code -} -\examples{ -\dontrun{ -# Short hand to get countries -get_countries() -} -} diff --git a/man/get_cpi.Rd b/man/get_cpi.Rd deleted file mode 100644 index eaa3038..0000000 --- a/man/get_cpi.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_cpi} -\alias{get_cpi} -\title{get_cpi()} -\usage{ -get_cpi( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of Consumer Price Index (CPI) values used for -poverty and inequality computations. -statistics -} -\examples{ -\dontrun{ -# Short hand to get cpi -get_cpi() -} -} diff --git a/man/get_dictionary.Rd b/man/get_dictionary.Rd deleted file mode 100644 index c0334f1..0000000 --- a/man/get_dictionary.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_dictionary} -\alias{get_dictionary} -\title{get_dictionary} -\usage{ -get_dictionary( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a data dictionary with a description of all variables -available through the PIP API. -} -\examples{ -\dontrun{ -# Short hand to get dictionary -get_dictionary() -} -} diff --git a/man/get_gdp.Rd b/man/get_gdp.Rd deleted file mode 100644 index b1cd274..0000000 --- a/man/get_gdp.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_gdp} -\alias{get_gdp} -\title{get_gdp()} -\usage{ -get_gdp( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of Growth Domestic Product (GDP) values used for -poverty and inequality statistics. -} -\examples{ -\dontrun{ -# Short hand to get gdp -get_gdp() -} -} diff --git a/man/get_hfce.Rd b/man/get_hfce.Rd deleted file mode 100644 index 5c267b2..0000000 --- a/man/get_hfce.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_hfce} -\alias{get_hfce} -\title{get_hfce} -\usage{ -get_hfce( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of Household Final Consumption Expenditure (HFCE) values -used for poverty and inequality computations. -} -\examples{ -\dontrun{ -# Short hand to get hfce -get_hfce() -} -} diff --git a/man/get_incgrp_coverage.Rd b/man/get_incgrp_coverage.Rd deleted file mode 100644 index 774632f..0000000 --- a/man/get_incgrp_coverage.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_incgrp_coverage} -\alias{get_incgrp_coverage} -\title{get_incgrp_coverage} -\usage{ -get_incgrp_coverage( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of survey coverage for low and lower-middle -income countries. If this coverage is less than 50\%, World level aggregate -statistics will not be computed. -} -\examples{ -\dontrun{ -# Short hand to get incgrp_coverage -get_incgrp_coverage() -} -} diff --git a/man/get_interpolated_means.Rd b/man/get_interpolated_means.Rd deleted file mode 100644 index 5434524..0000000 --- a/man/get_interpolated_means.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_interpolated_means} -\alias{get_interpolated_means} -\title{get_interpolated_means} -\usage{ -get_interpolated_means( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of key information and statistics for all years -for which poverty and inequality statistics are either available (household -survey exists) or extra- / interpolated. -Please see \code{\link{get_dictionary}} for more information about -each variable available in this table. -} -\examples{ -\dontrun{ -# Short hand to get interpolated_means -get_interpolated_means() -} -} diff --git a/man/get_pop.Rd b/man/get_pop.Rd deleted file mode 100644 index 39c1bad..0000000 --- a/man/get_pop.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_pop} -\alias{get_pop} -\title{get_pop} -\usage{ -get_pop( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of population values used for poverty and -inequality computations. -} -\examples{ -\dontrun{ -# Short hand to get pop -get_pop() -} -} diff --git a/man/get_pop_region.Rd b/man/get_pop_region.Rd deleted file mode 100644 index 6d9cb8f..0000000 --- a/man/get_pop_region.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_pop_region} -\alias{get_pop_region} -\title{get_pop_region} -\usage{ -get_pop_region( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of total population by region-year. These values -are used for the computation of regional aggregate poverty statistics. -} -\examples{ -\dontrun{ -# Short hand to get pop_region -get_pop_region() -} -} diff --git a/man/get_ppp.Rd b/man/get_ppp.Rd deleted file mode 100644 index a61630d..0000000 --- a/man/get_ppp.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_ppp} -\alias{get_ppp} -\title{get_ppp} -\usage{ -get_ppp( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of Purchasing Power Parity (PPP) values -used for poverty and inequality computations. -} -\examples{ -\dontrun{ -# Short hand to get ppp -get_ppp() -} -} diff --git a/man/get_region_coverage.Rd b/man/get_region_coverage.Rd deleted file mode 100644 index bc2d3cf..0000000 --- a/man/get_region_coverage.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_region_coverage} -\alias{get_region_coverage} -\title{get_region_coverage} -\usage{ -get_region_coverage( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Return a table of regional survey coverage: Percentage of -available surveys for a specific region-year. -} -\examples{ -\dontrun{ -# Short hand to get region_coverage -get_region_coverage() -} -} diff --git a/man/get_regions.Rd b/man/get_regions.Rd deleted file mode 100644 index bad0c4f..0000000 --- a/man/get_regions.Rd +++ /dev/null @@ -1,38 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_regions} -\alias{get_regions} -\title{get_regions} -\usage{ -get_regions( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table regional grouping used for computing aggregate -poverty statistics. -} -\examples{ -\dontrun{ -# Short hand to get regions -get_regions() -} -} diff --git a/man/get_survey_means.Rd b/man/get_survey_means.Rd deleted file mode 100644 index a8e8255..0000000 --- a/man/get_survey_means.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/get_aux.R -\name{get_survey_means} -\alias{get_survey_means} -\title{get_survey_means} -\usage{ -get_survey_means( - version = NULL, - ppp_version = NULL, - release_version = NULL, - api_version = "v1", - format = c("rds", "json", "csv"), - server = NULL -) -} -\arguments{ -\item{version}{character: Data version. See \code{get_versions()}} - -\item{ppp_version}{ppp year to be used} - -\item{release_version}{date when the data was published in YYYYMMDD format} - -\item{api_version}{character: API version} - -\item{format}{character: Response format either of c("rds", "json", "csv")} - -\item{server}{character: Server. For WB internal use only} -} -\description{ -Returns a table of all available surveys and associated key -statistics. Please see \code{\link{get_dictionary}} for more information about -each variable available in this table. -} -\examples{ -\dontrun{ -# Short hand to get survey_means -get_survey_means() -} -} From 5007a1eb2231eb18a4c40357111eacf5563f27f9 Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 10:57:22 -0400 Subject: [PATCH 5/9] improve description of returned data in get_aux --- R/get_aux.R | 14 ++++++++------ man/get_aux.Rd | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/get_aux.R b/R/get_aux.R index 58f6bf7..bab4396 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -1,10 +1,10 @@ #' Get auxiliary data #' #' @description `get_aux()` Get an auxiliary dataset. If no table is specified a -#' vector with possible inputs will be returned. +#' vector with possible inputs will be returned. #' -#' `get_countries()` Returns a table countries with their full names, ISO codes, -#' and associated region code +#' `get_countries()` Returns a table countries with their full names, ISO +#' codes, and associated region code #' #' #' @param table Aux table @@ -15,9 +15,11 @@ #' @inheritParams get_stats #' @param force logical: force replacement. Default is FALSE #' -#' @return tibble or list. If `assign_tb` is TRUE or character, it will return -#' TRUE if data was assign properly to .pip env. If `simplify = FALSE`, it -#' returns a list of class "pip_api" +#' @return If `simplify = FALSE`, it returns a list of class "pip_api". If +#' `simplify = TRUE`, it returns a tibble with the requested data. This is the +#' default. Only for `get_aux()`, If `assign_tb = TRUE` or character, it +#' returns TRUE when data was assign properly to .pip env. FALSE, if it was +#' not assigned. #' @export #' @examples #' \dontrun{ diff --git a/man/get_aux.Rd b/man/get_aux.Rd index e1d8ebf..385520d 100644 --- a/man/get_aux.Rd +++ b/man/get_aux.Rd @@ -173,16 +173,16 @@ character, the table will be assigned to that name.} \item{force}{logical: force replacement. Default is FALSE} } \value{ -tibble or list. If \code{assign_tb} is TRUE or character, it will return -TRUE if data was assign properly to .pip env. If \code{simplify = FALSE}, it -returns a list of class "pip_api" +If \code{assign_tb = TRUE} or character, it returns TRUE when data was +assign properly to .pip env. FALSE, if it was not assigned. If \code{simplify = FALSE}, it returns a list of class "pip_api". If \code{simplify = TRUE}, it +returns a tibble with the requested data. This is the default. } \description{ \code{get_aux()} Get an auxiliary dataset. If no table is specified a vector with possible inputs will be returned. -\code{get_countries()} Returns a table countries with their full names, ISO codes, -and associated region code +\code{get_countries()} Returns a table countries with their full names, ISO +codes, and associated region code } \section{Functions}{ \itemize{ From 1f57b97a7e39d3a365904efc98a1bc32e5cc5b4c Mon Sep 17 00:00:00 2001 From: "R.Andres Castaneda" Date: Tue, 2 May 2023 11:02:49 -0400 Subject: [PATCH 6/9] explain functions results further --- R/get_stats.R | 6 +++++- man/get_aux.Rd | 8 +++++--- man/get_stats.Rd | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/R/get_stats.R b/R/get_stats.R index b5782da..0b0a6a6 100644 --- a/R/get_stats.R +++ b/R/get_stats.R @@ -21,7 +21,11 @@ #' `tibble` #' @param server character: Server. For WB internal use only #' -#' @return tibble or list +#' @return If `simplify = FALSE`, it returns a list of class "pip_api". If +#' `simplify = TRUE`, it returns a tibble with the requested data. This is the +#' default. Only for `get_aux()`, If `assign_tb = TRUE` or character, it +#' returns TRUE when data was assign properly to .pip env. FALSE, if it was +#' not assigned. #' @export #' #' @examples diff --git a/man/get_aux.Rd b/man/get_aux.Rd index 385520d..60209ed 100644 --- a/man/get_aux.Rd +++ b/man/get_aux.Rd @@ -173,9 +173,11 @@ character, the table will be assigned to that name.} \item{force}{logical: force replacement. Default is FALSE} } \value{ -If \code{assign_tb = TRUE} or character, it returns TRUE when data was -assign properly to .pip env. FALSE, if it was not assigned. If \code{simplify = FALSE}, it returns a list of class "pip_api". If \code{simplify = TRUE}, it -returns a tibble with the requested data. This is the default. +If \code{simplify = FALSE}, it returns a list of class "pip_api". If +\code{simplify = TRUE}, it returns a tibble with the requested data. This is the +default. Only for \code{get_aux()}, If \code{assign_tb = TRUE} or character, it +returns TRUE when data was assign properly to .pip env. FALSE, if it was +not assigned. } \description{ \code{get_aux()} Get an auxiliary dataset. If no table is specified a diff --git a/man/get_stats.Rd b/man/get_stats.Rd index 4cf3799..d42902c 100644 --- a/man/get_stats.Rd +++ b/man/get_stats.Rd @@ -72,7 +72,11 @@ sub-groups. Either 'wb_regions' or 'none'.} \item{server}{character: Server. For WB internal use only} } \value{ -tibble or list +If \code{simplify = FALSE}, it returns a list of class "pip_api". If +\code{simplify = TRUE}, it returns a tibble with the requested data. This is the +default. Only for \code{get_aux()}, If \code{assign_tb = TRUE} or character, it +returns TRUE when data was assign properly to .pip env. FALSE, if it was +not assigned. } \description{ Get poverty and inequality statistics From c4956b66af29a1695bfcb5943af774dc20bb3d0b Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Wed, 3 May 2023 18:11:30 +0800 Subject: [PATCH 7/9] fix typo --- R/get_aux.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_aux.R b/R/get_aux.R index bab4396..ae70c65 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -100,7 +100,7 @@ get_aux <- function(table = NULL, tb_name <- assign_tb } else { - msg <- c("Invalid sintax in {.field assign_tb}", + msg <- c("Invalid syntax in {.field assign_tb}", "*" = "{.field assign_tb} must be logical or character.") cli::cli_abort(msg, wrap = TRUE) } From c0e17f695458e97cfde0b6fc32a6e108d26cd9b5 Mon Sep 17 00:00:00 2001 From: tonyfujs Date: Wed, 5 Jul 2023 14:24:35 +0200 Subject: [PATCH 8/9] update default value so it uses the API API default. --- R/get_stats.R | 2 +- man/get_stats.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/get_stats.R b/R/get_stats.R index 0b0a6a6..f350cf3 100644 --- a/R/get_stats.R +++ b/R/get_stats.R @@ -122,7 +122,7 @@ get_stats <- function(country = "all", #' @rdname get_stats #' @export get_wb <- function(year = "all", - povline = 1.9, + povline = NULL, version = NULL, ppp_version = NULL, release_version = NULL, diff --git a/man/get_stats.Rd b/man/get_stats.Rd index d42902c..921f9f9 100644 --- a/man/get_stats.Rd +++ b/man/get_stats.Rd @@ -25,7 +25,7 @@ get_stats( get_wb( year = "all", - povline = 1.9, + povline = NULL, version = NULL, ppp_version = NULL, release_version = NULL, From c2a436cce9c54c3008702d41ee0d365b7324a01a Mon Sep 17 00:00:00 2001 From: tonyfujs Date: Wed, 5 Jul 2023 14:25:12 +0200 Subject: [PATCH 9/9] fix outdated unit tests --- tests/testthat/test-get_aux.R | 2 +- tests/testthat/test-get_stats.R | 59 ++++++++++++--------------------- 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/tests/testthat/test-get_aux.R b/tests/testthat/test-get_aux.R index 4579f64..eee97b0 100644 --- a/tests/testthat/test-get_aux.R +++ b/tests/testthat/test-get_aux.R @@ -43,7 +43,7 @@ test_that("get_aux() works when calling specific tables", { # expect_true(is.list(get_aux("tmp", simplify = FALSE))) skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE") expect_error(get_aux("wrong-table-name", server = "qa")) - expect_true(is.list(get_aux("wrong-table-name", simplify = FALSE, server = "qa"))) + expect_true(is.list(get_aux("wrong-table-name", simplify = FALSE, server = "prod"))) # Check all tables skip("survey_metadata gives a 500 error. Need to add functionality for list data") diff --git a/tests/testthat/test-get_stats.R b/tests/testthat/test-get_stats.R index 9ba0900..2ee287f 100644 --- a/tests/testthat/test-get_stats.R +++ b/tests/testthat/test-get_stats.R @@ -62,13 +62,8 @@ test_that("get_stats() works w/ popshare option", { test_that("get_stats() works w/ subgroup = 'wb_regions'", { skip_if_offline() skip_on_cran() - skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", - message = "pip-grp not implement on PROD yet" - ) - skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), - message = "Could not connect to QA host" - ) - df <- get_stats("all", year = 2011, subgroup = "wb_regions", server = "qa") + + df <- get_stats("all", year = 2011, subgroup = "wb_regions", server = "prod") expect_equal(nrow(df), 10) expect_identical( sort(df$region_code), @@ -83,16 +78,14 @@ test_that("get_stats() works w/ subgroup = 'none'", { skip("Need to review to whole logic for this") skip_if_offline() skip_on_cran() - skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", - message = "pip-grp not implement on PROD yet" - ) - skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), - message = "Could not connect to QA host" - ) - df <- get_stats("all", year = 2011, subgroup = "none", server = "qa") + + # skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), + # message = "Could not connect to QA host" + # ) + df <- get_stats("all", year = 2011, subgroup = "none", server = "prod") expect_equal(nrow(df), 1) expect_identical(df$region_code, "CUSTOM") - df <- get_stats(c("ARG", "BRA"), year = 2011, subgroup = "none", server = "qa") + df <- get_stats(c("ARG", "BRA"), year = 2011, subgroup = "none", server = "prod") expect_equal(nrow(df), 1) expect_identical(df$region_code, "CUSTOM") }) @@ -149,13 +142,8 @@ test_that("get_stats() works w/ simplify = FALSE", { test_that("get_wb() works", { skip_if_offline() skip_on_cran() - skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", - message = "pip-grp not implement on PROD yet" - ) - skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), - message = "Could not connect to QA host" - ) - df <- get_wb(year = 2011, server = "qa") + + df <- get_wb(year = 2011, server = "prod") expect_equal(nrow(df), 10) expect_identical( sort(df$region_code), @@ -169,19 +157,14 @@ test_that("get_wb() works", { test_that("get_wb() works w/ all response formats", { skip_if_offline() skip_on_cran() - skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", - message = "pip-grp not implement on PROD yet" - ) - skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), - message = "Could not connect to QA host" - ) - df <- get_wb(year = "all", format = "json", server = "qa") + + df <- get_wb(year = "all", format = "json", server = "prod") expect_true(tibble::is_tibble(df)) expect_gte(nrow(df), 3) - df <- get_wb(year = "all", format = "csv", server = "qa") + df <- get_wb(year = "all", format = "csv", server = "prod") expect_true(tibble::is_tibble(df)) expect_gte(nrow(df), 3) - df <- get_wb(year = "all", format = "rds", server = "qa") + df <- get_wb(year = "all", format = "rds", server = "prod") expect_true(tibble::is_tibble(df)) expect_gte(nrow(df), 3) }) @@ -189,13 +172,13 @@ test_that("get_wb() works w/ all response formats", { test_that("get_wb() works w/ simplify = FALSE", { skip_if_offline() skip_on_cran() - skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", - message = "pip-grp not implement on PROD yet" - ) - skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), - message = "Could not connect to QA host" - ) - res <- get_wb(year = "all", simplify = FALSE, server = "qa") + # skip_if(Sys.getenv("PIPR_RUN_LOCAL_TESTS") != "TRUE", + # message = "pip-grp not implement on PROD yet" + # ) + # skip_if(is.null(curl::nslookup(qa_host, error = FALSE)), + # message = "Could not connect to QA host" + # ) + res <- get_wb(year = "all", simplify = FALSE, server = "prod") expect_true(is.list(res)) expect_identical(names(res), c("url", "status", "type", "content", "response")) expect_identical(class(res), "pip_api")