Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #41

Merged
merged 7 commits into from
Sep 26, 2022
Merged

Dev #41

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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: pipr
Title: Client for the PIP API
Version: 0.0.3
Version: 0.0.4
Authors@R:
c(person(given = "Tony",
family = "Fujs",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# pipr 0.0.4

* [Hot fix](https://github.com/worldbank/pipr/pull/40)

# pipr 0.0.3

* [Add new ppp_version and release_version parameters](https://github.com/worldbank/pipr/pull/38)
Expand Down
190 changes: 136 additions & 54 deletions R/get_aux.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
#' # Get countries
#' df <- get_aux("countries")
#' }
get_aux <- function(table = NULL, version = NULL, api_version = "v1",
get_aux <- function(table = NULL,
version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
simplify = TRUE, server = NULL) {

# Match args
api_version <- match.arg(api_version)
format <- match.arg(format)

# Check connection
check_internet()
check_api(api_version, server)

# Build query string
u <- build_url(server, "aux", api_version = api_version)

Expand All @@ -38,7 +38,11 @@ get_aux <- function(table = NULL, version = NULL, api_version = "v1",
res <- httr::GET(u)
parse_response(res, simplify = simplify)
} else {
args <- build_args(table = table, version = version, format = format)
args <- build_args(.table = table,
.version = version,
.ppp_version = ppp_version,
.release_version = release_version,
.format = format)
res <- httr::GET(u, query = args, httr::user_agent(pipr_user_agent))
parse_response(res, simplify = simplify)
}
Expand All @@ -54,11 +58,17 @@ get_aux <- function(table = NULL, version = NULL, api_version = "v1",
#' # Short hand to get countries
#' get_countries()
#' }
get_countries <- function(version = NULL, api_version = "v1",
get_countries <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("countries",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -74,11 +84,17 @@ get_countries <- function(version = NULL, api_version = "v1",
#' # Short hand to get regions
#' get_regions()
#' }
get_regions <- function(version = NULL, api_version = "v1",
get_regions <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("regions",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -95,11 +111,17 @@ get_regions <- function(version = NULL, api_version = "v1",
#' # Short hand to get cpi
#' get_cpi()
#' }
get_cpi <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_cpi <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("cpi",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -115,11 +137,17 @@ get_cpi <- function(version = NULL, api_version = "v1",
#' # Short hand to get dictionary
#' get_dictionary()
#' }
get_dictionary <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_dictionary <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("dictionary",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -135,11 +163,17 @@ get_dictionary <- function(version = NULL, api_version = "v1",
#' # Short hand to get gdp
#' get_gdp()
#' }
get_gdp <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_gdp <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("gdp",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -156,11 +190,17 @@ get_gdp <- function(version = NULL, api_version = "v1",
#' # Short hand to get incgrp_coverage
#' get_incgrp_coverage()
#' }
get_incgrp_coverage <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_incgrp_coverage <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("incgrp_coverage",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -179,11 +219,17 @@ get_incgrp_coverage <- function(version = NULL, api_version = "v1",
#' # Short hand to get interpolated_means
#' get_interpolated_means()
#' }
get_interpolated_means <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_interpolated_means <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("interpolated_means",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -199,11 +245,17 @@ get_interpolated_means <- function(version = NULL, api_version = "v1",
#' # Short hand to get hfce
#' get_hfce()
#' }
get_hfce <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_hfce <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("pce",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -218,11 +270,17 @@ get_hfce <- function(version = NULL, api_version = "v1",
#' # Short hand to get pop
#' get_pop()
#' }
get_pop <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_pop <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("pop",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -237,11 +295,17 @@ get_pop <- function(version = NULL, api_version = "v1",
#' # Short hand to get pop_region
#' get_pop_region()
#' }
get_pop_region <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_pop_region <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("pop_region",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -257,11 +321,17 @@ get_pop_region <- function(version = NULL, api_version = "v1",
#' # Short hand to get ppp
#' get_ppp()
#' }
get_ppp <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_ppp <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("ppp",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -276,11 +346,17 @@ get_ppp <- function(version = NULL, api_version = "v1",
#' # Short hand to get region_coverage
#' get_region_coverage()
#' }
get_region_coverage <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_region_coverage <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("region_coverage",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
Expand All @@ -297,11 +373,17 @@ get_region_coverage <- function(version = NULL, api_version = "v1",
#' # Short hand to get survey_means
#' get_survey_means()
#' }
get_survey_means <- function(version = NULL, api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_survey_means <- function(version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
server = NULL) {
get_aux("survey_means",
version = version, api_version = api_version,
version = version,
ppp_version = ppp_version,
release_version = release_version,
api_version = api_version,
format = format, server = server
)
}
40 changes: 22 additions & 18 deletions R/get_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ get_stats <- function(country = "all",

# Build query string
args <- build_args(
country = country,
year = year,
povline = povline,
popshare = popshare,
fill_gaps = fill_gaps,
group_by = group_by,
welfare_type = welfare_type,
reporting_level = reporting_level,
version = version,
ppp_version = ppp_version,
release_version = release_version,
format = format
.country = country,
.year = year,
.povline = povline,
.popshare = popshare,
.fill_gaps = fill_gaps,
.group_by = group_by,
.welfare_type = welfare_type,
.reporting_level = reporting_level,
.version = version,
.ppp_version = ppp_version,
.release_version = release_version,
.format = format
)
u <- build_url(server, endpoint, api_version)
# Send query
Expand All @@ -120,6 +120,8 @@ get_stats <- function(country = "all",
get_wb <- function(year = "all",
povline = 1.9,
version = NULL,
ppp_version = NULL,
release_version = NULL,
api_version = "v1",
format = c("rds", "json", "csv"),
simplify = TRUE,
Expand All @@ -129,14 +131,16 @@ get_wb <- function(year = "all",
api_version <- match.arg(api_version)
format <- match.arg(format)

# Check connection
check_internet()
check_api(api_version, server)

# Build query string
args <- build_args(
country = "all", year = year, povline = povline,
group_by = "wb", version = version, format = format
.country = "all",
.year = year,
.povline = povline,
.group_by = "wb",
.version = version,
.ppp_version = ppp_version,
.release_version = release_version,
.format = format
)
u <- build_url(server, "pip-grp", api_version)

Expand Down
Loading