From f6764b9c7f43142075a62e2e5fa018bf8c57c0e6 Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Fri, 11 Aug 2023 22:37:39 +0800 Subject: [PATCH 1/4] default value from options --- R/display_aux.R | 6 +++--- R/get_aux.R | 8 ++++---- R/get_stats.R | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/R/display_aux.R b/R/display_aux.R index d8e9105..c97d273 100644 --- a/R/display_aux.R +++ b/R/display_aux.R @@ -12,9 +12,9 @@ #' \dontrun{ #' display_aux() #' } -display_aux <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +display_aux <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, diff --git a/R/get_aux.R b/R/get_aux.R index ae70c65..d7ffbe8 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -45,10 +45,10 @@ #' get_aux("gdp", assign_tb = "new_name") #' #' } -get_aux <- function(table = NULL, - version = NULL, - ppp_version = NULL, - release_version = NULL, +get_aux <- function(table = getOption("pipr.table"), + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, diff --git a/R/get_stats.R b/R/get_stats.R index f350cf3..7ed0696 100644 --- a/R/get_stats.R +++ b/R/get_stats.R @@ -65,9 +65,9 @@ get_stats <- function(country = "all", subgroup = NULL, welfare_type = c("all", "income", "consumption"), reporting_level = c("all", "national", "urban", "rural"), - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, From c438692fbefa39089776608e2768b5262b9886fc Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Sat, 12 Aug 2023 10:04:09 +0800 Subject: [PATCH 2/4] update docs and other functions --- R/get_aux.R | 78 ++++++++++++++++++++--------------------- man/display_aux.Rd | 6 ++-- man/get_aux.Rd | 86 +++++++++++++++++++++++----------------------- man/get_stats.Rd | 6 ++-- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/R/get_aux.R b/R/get_aux.R index d7ffbe8..e476c61 100644 --- a/R/get_aux.R +++ b/R/get_aux.R @@ -141,9 +141,9 @@ get_aux <- function(table = getOption("pipr.table"), #' # Short hand to get countries #' get_countries() #' } -get_countries <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_countries <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -164,9 +164,9 @@ get_countries <- function(version = NULL, #' # Short hand to get regions #' get_regions() #' } -get_regions <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_regions <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -187,9 +187,9 @@ get_regions <- function(version = NULL, #' # Short hand to get cpi #' get_cpi() #' } -get_cpi <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_cpi <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -210,9 +210,9 @@ get_cpi <- function(version = NULL, #' # Short hand to get dictionary #' get_dictionary() #' } -get_dictionary <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_dictionary <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -233,9 +233,9 @@ get_dictionary <- function(version = NULL, #' # Short hand to get gdp #' get_gdp() #' } -get_gdp <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_gdp <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -257,9 +257,9 @@ get_gdp <- function(version = NULL, #' # Short hand to get incgrp_coverage #' get_incgrp_coverage() #' } -get_incgrp_coverage <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_incgrp_coverage <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -283,9 +283,9 @@ get_incgrp_coverage <- function(version = NULL, #' # Short hand to get interpolated_means #' get_interpolated_means() #' } -get_interpolated_means <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_interpolated_means <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -305,9 +305,9 @@ get_interpolated_means <- function(version = NULL, #' # Short hand to get hfce #' get_hfce() #' } -get_hfce <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_hfce <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -327,9 +327,9 @@ get_hfce <- function(version = NULL, #' # Short hand to get pop #' get_pop() #' } -get_pop <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_pop <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -350,9 +350,9 @@ get_pop <- function(version = NULL, #' # Short hand to get pop_region #' get_pop_region() #' } -get_pop_region <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_pop_region <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -373,9 +373,9 @@ get_pop_region <- function(version = NULL, #' # Short hand to get ppp #' get_ppp() #' } -get_ppp <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_ppp <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -395,9 +395,9 @@ get_ppp <- function(version = NULL, #' # Short hand to get region_coverage #' get_region_coverage() #' } -get_region_coverage <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_region_coverage <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { @@ -419,9 +419,9 @@ get_region_coverage <- function(version = NULL, #' # Short hand to get survey_means #' get_survey_means() #' } -get_survey_means <- function(version = NULL, - ppp_version = NULL, - release_version = NULL, +get_survey_means <- function(version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL) { diff --git a/man/display_aux.Rd b/man/display_aux.Rd index ba5e598..35ded18 100644 --- a/man/display_aux.Rd +++ b/man/display_aux.Rd @@ -5,9 +5,9 @@ \title{Display available auxiliary tables} \usage{ display_aux( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, diff --git a/man/get_aux.Rd b/man/get_aux.Rd index 60209ed..38d0ffc 100644 --- a/man/get_aux.Rd +++ b/man/get_aux.Rd @@ -18,10 +18,10 @@ \title{Get auxiliary data} \usage{ get_aux( - table = NULL, - version = NULL, - ppp_version = NULL, - release_version = NULL, + table = getOption("pipr.table"), + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, @@ -31,117 +31,117 @@ get_aux( ) get_countries( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_regions( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_cpi( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_dictionary( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_gdp( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_incgrp_coverage( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_interpolated_means( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_hfce( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_pop( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_pop_region( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_ppp( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_region_coverage( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL ) get_survey_means( - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), server = NULL diff --git a/man/get_stats.Rd b/man/get_stats.Rd index 921f9f9..4d25945 100644 --- a/man/get_stats.Rd +++ b/man/get_stats.Rd @@ -14,9 +14,9 @@ get_stats( subgroup = NULL, welfare_type = c("all", "income", "consumption"), reporting_level = c("all", "national", "urban", "rural"), - version = NULL, - ppp_version = NULL, - release_version = NULL, + version = getOption("pipr.version"), + ppp_version = getOption("pipr.ppp_version"), + release_version = getOption("pipr.release_version"), api_version = "v1", format = c("rds", "json", "csv"), simplify = TRUE, From ccd2d9b48da5f12fe48f743a3ccd946418c65dac Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Sat, 12 Aug 2023 10:09:22 +0800 Subject: [PATCH 3/4] update NEWS file --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a577330..f9b4bad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: pipr Title: Client for the Poverty and Inequality Platform ('PIP') API -Version: 1.0.0 +Version: 1.0.1 Authors@R: c(person(given = "Tony", family = "Fujs", diff --git a/NEWS.md b/NEWS.md index a3798ea..0256edc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# pipr 1.0.1 + +* Introduce setting default values for arguments `table`, `version`, `ppp_version` and `release_version` using `options` + # pipr 1.0.0 * [Mock live API calls or skip them on CRAN](https://github.com/worldbank/pipr/pull/45) From d98d6bb9944b731b727dfc675b86b3b34aee8e9b Mon Sep 17 00:00:00 2001 From: Ronak Shah Date: Sat, 19 Aug 2023 10:07:55 +0800 Subject: [PATCH 4/4] set default options on Load --- R/zzz.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index f6a0d22..44e1092 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,3 +1,9 @@ +pipr_default_options <- list( + pipr.version = NULL, + pipr.ppp_version = NULL, + pipr.release_version = NULL, + pipr.table = NULL +) .onLoad <- function(libname, pkgname) { if (!Sys.getenv("PIPR_DISABLE_CACHING") == "TRUE") { @@ -11,9 +17,12 @@ get_aux <<- memoise::memoise(get_aux, cache = cm) get_versions <<- memoise::memoise(get_versions, cache = cm) } + op <- options() + toset <- !(names(pipr_default_options) %in% names(op)) + if (any(toset)) options(pipr_default_options[toset]) options(cli.ignore_unknown_rstudio_theme = TRUE) - + invisible() } .onAttach <- function(libname, pkgname) {