World_R6: R6 Class representing a world.

World_R6R Documentation

R6 Class representing a world.

Description

An instance or object of class world is expected to contain (house) objects from class Country_R6 The methods in this class should merge the data from all added objects and summarise/present them.

Format

An [R6::R6Class] object.

Public fields

country_name

the name of the country being added. This name should be the one used in creating the Country_R6 object.

country_data

a list housing (to house) clones (copies) of the instance (object) of class Country_R6 being added.

world_data

a tibble containing data from all added countries

world_map

an object of class leaflet (A leaflet map).

world_stats

a tibble containing the counts of health facilities (by type)

Methods

Public methods


Method add_country()

Add country object (of class Country_R6) to this object

Usage
World_R6$add_country(country_name, country_object)
Arguments
country_name

The name of the country to which the country_object will be associated

country_object

An object, instance of class Country_R6 that contain the data from the APIs for the added country.

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 in the global environment:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
Kenya <- Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())

# Query the healthsities API:
Kenya$
    query_health_facilities()

# Add a clone of the Country_R6 object \code{Kenya} to the World_R6:
object \code{World}
World$add_country(
      country_name = "Kenya",
      country_object = Kenya)

# Country_R6 object do not need to be created in the global env.
# Below we create an object of class Country_R6 while adding it to
# World_R6 object:
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
}

Method update_world_data()

Update World data on health sites. This method is usually helpful after a Country_R6 object has queried its health facilities

Usage
World_R6$update_world_data(country_name)
Arguments
country_name

The name of the country for which the method will update the world's data.

Returns

Nothing back to the user, but updates world_data, world_map and world_stats.

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Update world data:
World$update_world_data(country_name = "Kenya")
}

Method get_country_data()

Get data from a specific country in the World_R6 class

Usage
World_R6$get_country_data(country_name)
Arguments
country_name

The name of the country for which the method will retrieve the data.

Returns

A tibble with the specified country health sites data

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request some of Kenya's data back:
World$get_country_data(country_name = "Kenya")
}

Method get_country_map()

Get the map showing health facilities in a specific country.

Usage
World_R6$get_country_map(country_name)
Arguments
country_name

The name of the country for which the method will retrieve the map

Returns

An object of class leaflet (A leaflet map)

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request Kenya's health facilities map:
World$get_country_map(country_name = "Kenya")
}

Method get_world_data()

Get the map showing health facilities in a all added country.

Usage
World_R6$get_world_data()
Returns

An object of class leaflet (A leaflet map)

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request available (of all included countries) health facilities
data:
World$get_world_data(country_name = "Kenya")
}

Method get_world_stats()

Get the counts/numbers of health facilities by country name and facility type.

Usage
World_R6$get_world_stats()
Returns

A tibble containing the request stats

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request available (of all included countries) health facilities
stats:
World$get_world_stats(country_name = "Kenya")
}

Method get_world_map()

Get a map showing health facilities in all added countries

Usage
World_R6$get_world_map()
Returns

An object of class leaflet (A leaflet map)

Examples
\dontrun{
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request map of available health facilities from all countries
added to the World object
:
World$get_world_map(country_name = "Kenya")
}

Method clone()

The objects of this class are cloneable with this method.

Usage
World_R6$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

## End(Not run)

## ------------------------------------------------
## Method `World_R6$add_country`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 in the global environment:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
Kenya <- Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())

# Query the healthsities API:
Kenya$
    query_health_facilities()

# Add a clone of the Country_R6 object \code{Kenya} to the World_R6:
object \code{World}
World$add_country(
      country_name = "Kenya",
      country_object = Kenya)

# Country_R6 object do not need to be created in the global env.
# Below we create an object of class Country_R6 while adding it to
# World_R6 object:
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

## End(Not run)

## ------------------------------------------------
## Method `World_R6$update_world_data`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Update world data:
World$update_world_data(country_name = "Kenya")

## End(Not run)

## ------------------------------------------------
## Method `World_R6$get_country_data`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request some of Kenya's data back:
World$get_country_data(country_name = "Kenya")

## End(Not run)

## ------------------------------------------------
## Method `World_R6$get_country_map`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate a copy of class Country_R6 within the World object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request Kenya's health facilities map:
World$get_country_map(country_name = "Kenya")

## End(Not run)

## ------------------------------------------------
## Method `World_R6$get_world_data`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request available (of all included countries) health facilities
data:
World$get_world_data(country_name = "Kenya")

## End(Not run)

## ------------------------------------------------
## Method `World_R6$get_world_stats`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request available (of all included countries) health facilities
stats:
World$get_world_stats(country_name = "Kenya")

## End(Not run)

## ------------------------------------------------
## Method `World_R6$get_world_map`
## ------------------------------------------------

## Not run: 
# Instantiate a copy of class World_R6:
World <- World_R6$new()

# Instantiate two objects of class Country_R6 within the World
object:
# Note: the following example assumes that the user had set their
# healthsites API key into their environment using set_hs_API_key()
World$add_country(
      country_name = "Kenya",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )
World$add_country(
      country_name = "Zambia",
      country_object = Country_R6$new(
               country_name = "Kenya",
               hs_API_key = get_hs_API_key())$
      query_health_facilities()
      )

# Request map of available health facilities from all countries
added to the World object
:
World$get_world_map(country_name = "Kenya")

## End(Not run)

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