Country_R6: R6 Class representing a country.

Country_R6R Documentation

R6 Class representing a country.

Description

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.

Format

An [R6::R6Class] object.

Public fields

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'

Methods

Public methods


Method 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

Usage
Country_R6$new(country_name, hs_API_key = NULL, shiny_ = FALSE)
Arguments
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

Returns

A new 'Country_R6' object.

Examples
\dontrun{
# Instantiate a copy of class Country_R6:
Kenya <- Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())
}

Method initiate_APIs()

The initial query of user selected APIs

Usage
Country_R6$initiate_APIs(API_name_ = c("HS", "DHS", "WB", "GHO"))
Arguments
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).

Returns

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.

Examples
\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")
   )
}

Method initiate_GHO_API()

Query Global Health Observatory (GHO) API

Usage
Country_R6$initiate_GHO_API()
Returns

Nothing to the user, but populates several fields in the object calling the method

Examples
\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()
}

Method initiate_DHS_API()

Query Demographic and Health Surveys (DHS) API

Usage
Country_R6$initiate_DHS_API()
Returns

Nothing to the user, but populates several fields in the object calling the method

Examples
\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()
}

Method initiate_WB_API()

Query World bank (WB) API

Usage
Country_R6$initiate_WB_API()
Returns

Nothing to the user, but populates several fields in the object calling the method

Examples
\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()
}

Method initiate_HS_API()

Query Healthsities (HS) API

Usage
Country_R6$initiate_HS_API()
Returns

Nothing to the user, but populates several fields in the object calling the method

Examples
\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()
}

Method set_wb_data()

Get data from a specific socio-economic data from the World Bank

Usage
Country_R6$set_wb_data(indicator_label, date_from = 1960, date_to = 2022)
Arguments
indicator_label

WB indicator name or indicator label.

date_from

Range of data required, start date

date_to

Range of data required, end date

Returns

A tibble with data form the World Bank

Examples
\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")
}

Method get_dhs_survey_data()

Get data from a specific survey

Usage
Country_R6$get_dhs_survey_data(survey)
Arguments
survey

DHS survey year.

Returns

A tibble containing data from all country-specific DHS surveys

Examples
\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"
   )
}

Method get_dhs_ind_data()

Get data for a specific health indicator from DHS

Usage
Country_R6$get_dhs_ind_data(indicator_name, filter_var)
Arguments
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.

Returns

A tibble containing indicator-specific data from the country's DHS surveys

Examples
\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"
   )
}

Method get_wb_ind_data()

Get data from a specific socio-economic data from the World Bank

Usage
Country_R6$get_wb_ind_data()
Returns

A tibble containing the country indicator-specific data fetched from the World Bank API

Examples
\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()
}

Method get_facilities_data()

Get health facilities' data

Usage
Country_R6$get_facilities_data()
Returns

A tibble containing unmodified country-specific health facilities information

Examples
\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()
}

Method get_facilities_stats()

Get health facilities' counts

Usage
Country_R6$get_facilities_stats()
Returns

A tibble containing country-specific health facilities numbers/stats by facility type

Examples
\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()
}

Method get_facilities_map()

Get health facilities' map

Usage
Country_R6$get_facilities_map()
Returns

An object of class leaflet (A leaflet map)

Examples
\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()
}

Method get_gho_ind_list()

Get the indicators from the GHO API

Usage
Country_R6$get_gho_ind_list()
Returns

a tibble of GHO indicators (names and codes).

Examples
\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()
}

Method get_gho_ind_data()

Get country-specific indicator data for the GHO API

Usage
Country_R6$get_gho_ind_data(indicator_code_)
Arguments
indicator_code_

the GHO code used to refer to the indicator of interest

Returns

A tibble containing the indicator name, label, and value

Examples
\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"
    )
}

Method clone()

The objects of this class are cloneable with this method.

Usage
Country_R6$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## 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)

dark-peak-analytics/who_decide_AP documentation built on May 25, 2022, 8:31 p.m.