Country_R6 | R Documentation |
Objects of class Country_R6 provide a chance for the user to call any
of the supported APIs for their country of interest. Each instance of
class Country_R6 is country-specific, and it follows that the main
requirement to create or instantiate a copy of this class is the
country's name (see the new
method for an example). While some
countries might have more than one name, the Country_R6 class does not
have any control over the name accepted by the APIs. Also, it is
noteworthy to highlight that the response of the API might differ based
on the country name used. The new
method informs the user about
the availability of data for their respective country (or country
name); therefore, the user can experiment with different names for
their country of interest and gage which of the names is globally
accepted by the APIs.
An [R6::R6Class] object.
country_code
the iso2 and iso3 codes for the country of interest
data_status
bolean for whether data exists in a specific API
dhs_survey_years
years of DHS surveys for the country
dhs_survey_ids
the labels (ids) of DHS surveys for the country
dhs_indicators
the names of indicators available from the country's DHS surveys
dhs_data
all country DHS data available via the dhs API
gho_indicators
list of all GHO API indicators
gho_data
country GHO API indicator data
wb_auxiliaries
all World Bank auxiliary data
wb_indicators
all World Bank indicators available via the World Bank API
wb_data
the indicator specific data retrieved from via the World Bank API
health_facilities_data
all country-specific health facilities information fetched from the healthsites.io API
health_facilities_stats
country-specifc health facilities' numbers by type
health_facilities_map
a map showing country-specific health facilities'
new()
Initialisation method (triggered when a new object is created). This function checks whether data is available, allowing users to quickly see whether or not it is possible to call the API
Country_R6$new(country_name, hs_API_key = NULL, shiny_ = FALSE)
country_name
The name of the country for which the APIs will be queried.
hs_API_key
Healthsites API key/token. The API seems to work with any string passed to it. This behaviour might change in the future and this method is written to handle calls using valid keys
shiny_
Logical, if TRUE, function will suppress some messages; otherwise, the function will print useful information to the console
A new 'Country_R6' object.
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) }
initiate_APIs()
The initial query of user selected APIs
Country_R6$initiate_APIs(API_name_ = c("HS", "DHS", "WB", "GHO"))
API_name_
A string or vector of strings with the abbreviation of the API to start querying. Accepted values are Global Health Observatory (GHO), Demographic and Health Surveys (DHS), World bank (WB), and Healthsities (HS).
Nothing back to the user, but populates several internal
fields based on the API_name_
passed to the function. These
could include GHO (for example gho_indicators), DHS (for example
dhs_indicators), WB (for example wb_indicators) and HS (for example
health_facilities_data) objects.
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API queries for HS, DHS, WB, and GHO: Kenya$ initiate_APIs( API_name_ = c("HS", "DHS", "WB", "GHO") ) }
initiate_GHO_API()
Query Global Health Observatory (GHO) API
Country_R6$initiate_GHO_API()
Nothing to the user, but populates several fields in the object calling the method
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_GHO_API() }
initiate_DHS_API()
Query Demographic and Health Surveys (DHS) API
Country_R6$initiate_DHS_API()
Nothing to the user, but populates several fields in the object calling the method
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_DHS_API() }
initiate_WB_API()
Query World bank (WB) API
Country_R6$initiate_WB_API()
Nothing to the user, but populates several fields in the object calling the method
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_WB_API() }
initiate_HS_API()
Query Healthsities (HS) API
Country_R6$initiate_HS_API()
Nothing to the user, but populates several fields in the object calling the method
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_HS_API() }
set_wb_data()
Get data from a specific socio-economic data from the World Bank
Country_R6$set_wb_data(indicator_label, date_from = 1960, date_to = 2022)
indicator_label
WB indicator name or indicator label.
date_from
Range of data required, start date
date_to
Range of data required, end date
A tibble with data form the World Bank
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_WB_API() Kenya$ set_wb_data(indicator_label = "C1.12") }
get_dhs_survey_data()
Get data from a specific survey
Country_R6$get_dhs_survey_data(survey)
survey
DHS survey year.
A tibble containing data from all country-specific DHS surveys
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_DHS_API() Kenya$ get_dhs_survey_data( survey = 1989, filter_var = "SurveyYear" ) }
get_dhs_ind_data()
Get data for a specific health indicator from DHS
Country_R6$get_dhs_ind_data(indicator_name, filter_var)
indicator_name
DHS indicator name or indicator label.
filter_var
Either IndicatorId (default if nothing was supplied) or Indicator. This variable is used by the function to filter the data accordingly.
A tibble containing indicator-specific data from the country's DHS surveys
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_DHS_API() Kenya$ get_dhs_ind_data( indicator_name = "FE_FRTR_W_A15", filter_var = "IndicatorId" ) }
get_wb_ind_data()
Get data from a specific socio-economic data from the World Bank
Country_R6$get_wb_ind_data()
A tibble containing the country indicator-specific data fetched from the World Bank API
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_WB_API() Kenya$ set_wb_data(indicator_label = "C1.12")$ get_wb_ind_data() }
get_facilities_data()
Get health facilities' data
Country_R6$get_facilities_data()
A tibble containing unmodified country-specific health facilities information
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_data() }
get_facilities_stats()
Get health facilities' counts
Country_R6$get_facilities_stats()
A tibble containing country-specific health facilities numbers/stats by facility type
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_stats() }
get_facilities_map()
Get health facilities' map
Country_R6$get_facilities_map()
An object of class leaflet (A leaflet map)
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_map() }
get_gho_ind_list()
Get the indicators from the GHO API
Country_R6$get_gho_ind_list()
a tibble of GHO indicators (names and codes).
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_GHO_API() Kenya$ get_gho_ind_list() }
get_gho_ind_data()
Get country-specific indicator data for the GHO API
Country_R6$get_gho_ind_data(indicator_code_)
indicator_code_
the GHO code used to refer to the indicator of interest
A tibble containing the indicator name, label, and value
\dontrun{ # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_GHO_API() Kenya$ get_gho_ind_data( indicator_code_ = "WHOSIS_000001" ) }
clone()
The objects of this class are cloneable with this method.
Country_R6$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Country_R6$new` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$initiate_APIs` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API queries for HS, DHS, WB, and GHO: Kenya$ initiate_APIs( API_name_ = c("HS", "DHS", "WB", "GHO") ) ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$initiate_GHO_API` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_GHO_API() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$initiate_DHS_API` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_DHS_API() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$initiate_WB_API` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_WB_API() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$initiate_HS_API` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) # Initiate API: Kenya$ initiate_HS_API() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$set_wb_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_WB_API() Kenya$ set_wb_data(indicator_label = "C1.12") ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_dhs_survey_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_DHS_API() Kenya$ get_dhs_survey_data( survey = 1989, filter_var = "SurveyYear" ) ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_dhs_ind_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_DHS_API() Kenya$ get_dhs_ind_data( indicator_name = "FE_FRTR_W_A15", filter_var = "IndicatorId" ) ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_wb_ind_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_WB_API() Kenya$ set_wb_data(indicator_label = "C1.12")$ get_wb_ind_data() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_facilities_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_data() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_facilities_stats` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_stats() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_facilities_map` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_HS_API() Kenya$ get_facilities_map() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_gho_ind_list` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_GHO_API() Kenya$ get_gho_ind_list() ## End(Not run) ## ------------------------------------------------ ## Method `Country_R6$get_gho_ind_data` ## ------------------------------------------------ ## Not run: # Instantiate a copy of class Country_R6: Kenya <- Country_R6$new( country_name = "Kenya", hs_API_key = get_hs_API_key()) Kenya$ initiate_GHO_API() Kenya$ get_gho_ind_data( indicator_code_ = "WHOSIS_000001" ) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.