Skip to content

Commit

Permalink
Merge pull request #66 from worldbank/DEV
Browse files Browse the repository at this point in the history
Everything looks good. Thanks.
  • Loading branch information
randrescastaneda authored Jul 6, 2023
2 parents 035683b + 61b3ff6 commit e0b40dc
Show file tree
Hide file tree
Showing 24 changed files with 356 additions and 651 deletions.
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -14,23 +14,24 @@ Authors@R:
family = "Shah",
role = "aut",
email = "[email protected]"),
person(given = "R. Andrés",
person(given = "R.Andrés",
family = "Castañeda",
role = "aut",
email = "[email protected]"),
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
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,
<https://pip.worldbank.org/api>
BugReports: https://github.com/worldbank/pipr/issues
Suggests:
covr,
Expand Down
13 changes: 0 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 2 additions & 7 deletions R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -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)
}

}
Expand Down
123 changes: 45 additions & 78 deletions R/get_aux.R
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -11,8 +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
#' @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{
Expand Down Expand Up @@ -93,9 +100,9 @@ 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, class = "pipr_error", wrap = TRUE)
cli::cli_abort(msg, wrap = TRUE)
}

srt <- set_aux(table = tb_name,
Expand All @@ -116,7 +123,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)

}

Expand All @@ -127,11 +134,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
Expand All @@ -153,11 +157,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
Expand All @@ -179,12 +180,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
Expand All @@ -206,11 +203,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
Expand All @@ -232,11 +226,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
Expand All @@ -258,12 +249,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
Expand All @@ -285,14 +273,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
Expand All @@ -313,12 +298,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
Expand All @@ -339,11 +320,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
Expand All @@ -364,11 +342,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
Expand All @@ -390,11 +366,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
Expand All @@ -415,11 +388,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
Expand All @@ -441,12 +411,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
Expand Down
8 changes: 6 additions & 2 deletions R/get_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -118,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,
Expand Down
7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e0b40dc

Please sign in to comment.