| Title: | Data Science Infrastructure for Global Health in R |
| Version: | 0.2.0 |
| Description: | Tools for global health data analysis, including a publication-ready 'ggplot2' theme, a 'flextable' defaults helper, a thin pie chart wrapper, built-in regional country-code datasets, and convenience clients for the World Health Organization Global Health Observatory (GHO) OData API https://ghoapi.azureedge.net/api/ and the United Nations Sustainable Development Goals (SDG) API https://unstats.un.org/SDGAPI/swagger/. |
| License: | MIT + file LICENSE |
| Language: | en-US |
| URL: | https://github.com/shanlong-who/DSIR |
| BugReports: | https://github.com/shanlong-who/DSIR/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1.0) |
| Imports: | ggplot2 (≥ 3.4.0), flextable (≥ 0.9.0), httr2, rlang, cli |
| Suggests: | patchwork, officer, testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| LazyData: | true |
| NeedsCompilation: | no |
| Packaged: | 2026-04-14 15:12:31 UTC; User |
| Author: | Shanlong WHO [aut, cre] |
| Maintainer: | Shanlong WHO <dings@who.int> |
| Repository: | CRAN |
| Date/Publication: | 2026-04-21 20:22:19 UTC |
DSIR: Data Science Infrastructure for Global Health in R
Description
A small, opinionated toolkit for global health data analysis.
It bundles a publication-ready ggplot2 theme (theme_dsi()),
sensible flextable defaults (dsi_flextable_defaults()),
a quick pie chart helper (ggpie()), regional country-code
datasets (wpro_cty), and thin clients for the WHO Global Health
Observatory API (gho_indicators(), gho_data(),
gho_dimensions()) and the UN Sustainable Development Goals API
(sdg_goals(), sdg_targets(), sdg_indicators(), sdg_areas(),
sdg_data()).
Author(s)
Maintainer: Shanlong WHO dings@who.int
See Also
Useful links:
Set DSIR Flextable Defaults
Description
Applies a consistent set of flextable formatting defaults for
publication-ready tables (booktabs theme, bold headers, modest
padding). Pick any font you like — the default "" leaves the
flextable default in place so the call is safe on systems where
Cambria is not installed.
Usage
dsi_flextable_defaults(
font_size = 12,
font_family = "",
font_color = "#333333",
border_color = "black",
padding = c(3, 3, 4, 4)
)
Arguments
font_size |
Font size in points. Default |
font_family |
Font family name. Default |
font_color |
Font color. Default |
border_color |
Border color. Default |
padding |
Numeric vector of length 1 (applied to all sides)
or length 4 ( |
Value
Invisibly returns NULL. Called for its side effect of
mutating the flextable global defaults via
flextable::set_flextable_defaults().
Examples
dsi_flextable_defaults()
Create a Pie Chart with ggplot2
Description
Builds a pie chart from a data frame using one categorical column and one numeric column. Slices are labeled with the category name and percentage share.
Usage
ggpie(
df,
.x,
.y,
.offset = 1,
.color = "white",
.legend = FALSE,
.label = TRUE,
.label_size = 3.5
)
Arguments
df |
A data frame. |
.x |
Column name (string) of the categorical variable used for the slices. |
.y |
Column name (string) of the numeric variable used for the slice values. |
.offset |
Bar |
.color |
Border color between slices. Default |
.legend |
Logical. Show the legend? Default |
.label |
Logical. Draw |
.label_size |
Label text size in mm. Default |
Value
A ggplot object.
Examples
df <- data.frame(
category = c("A", "B", "C"),
value = c(40, 35, 25)
)
ggpie(df, "category", "value")
Fetch GHO Data
Description
Retrieves observations for a specific indicator from the WHO GHO OData API, with optional filters by spatial level, country / region and year range.
Usage
gho_data(
indicator,
spatial_type = NULL,
area = NULL,
year_from = NULL,
year_to = NULL
)
Arguments
indicator |
Character scalar. The indicator code
(e.g. |
spatial_type |
Character. Spatial dimension to filter on:
one of |
area |
Character vector of country or region codes
(e.g. |
year_from |
Numeric. Start year filter (inclusive).
Default |
year_to |
Numeric. End year filter (inclusive).
Default |
Value
A data frame of indicator observations, or an empty data frame when the service is unreachable.
See Also
gho_indicators(), gho_dimensions().
Examples
## Not run:
# Country-level data for one indicator
gho_data("NCDMORT3070", spatial_type = "country")
# Specific countries and years
gho_data("WHOSIS_000001", area = c("FRA", "DEU"), year_from = 2015)
## End(Not run)
List Dimensions of a GHO Indicator
Description
Returns the unique values of a given dimension across all
observations of a GHO indicator. Useful for discovering which
ages, sexes, regions, or other breakdowns are available before
calling gho_data().
Usage
gho_dimensions(indicator, dimension = "SpatialDimType")
Arguments
indicator |
Character scalar. The indicator code
(e.g. |
dimension |
Character. Name of the dimension column in the
indicator data. Common values include |
Value
A character vector of unique, sorted dimension values, or an empty character vector when the service is unreachable or the dimension is missing.
See Also
Examples
## Not run:
gho_dimensions("NCDMORT3070")
gho_dimensions("NCDMORT3070", dimension = "Dim1")
## End(Not run)
List GHO Indicators
Description
Fetches the catalog of indicators from the WHO Global Health Observatory (GHO) OData API.
Usage
gho_indicators(search = NULL)
Arguments
search |
Optional character string. If supplied, only
indicators whose name contains |
Value
A data frame with columns IndicatorCode,
IndicatorName and Language. Returns an empty data frame
(with a message) when the service is unreachable.
See Also
Examples
## Not run:
# All indicators
inds <- gho_indicators()
# Search by keyword
gho_indicators("mortality")
## End(Not run)
List SDG Geographic Areas
Description
Fetches the list of geographic areas available from the UN SDG database.
Usage
sdg_areas()
Value
A data frame with area codes and names, or NULL when
the service is unreachable.
See Also
Examples
## Not run:
sdg_areas()
## End(Not run)
Fetch SDG Data
Description
Retrieves data for one or more SDG indicators from the UN SDG API, with optional filters by area and year.
Usage
sdg_data(
indicator,
area = NULL,
year_from = NULL,
year_to = NULL,
page_size = 1000L
)
Arguments
indicator |
Character vector of indicator codes
(e.g. |
area |
Character vector of area codes (e.g.
|
year_from |
Numeric. Start year filter (inclusive).
Default |
year_to |
Numeric. End year filter (inclusive).
Default |
page_size |
Integer. Number of records per page.
Default |
Value
A data frame of indicator observations, or an empty data frame when the service is unreachable or there are no matching rows.
See Also
sdg_indicators(), sdg_areas().
Examples
## Not run:
# All data for indicator 1.1.1
sdg_data("1.1.1")
# Specific area and year range
sdg_data("3.2.1", area = "156", year_from = 2015, year_to = 2023)
## End(Not run)
List SDG Goals
Description
Fetches the list of Sustainable Development Goals from the UN SDG API.
Usage
sdg_goals(include_children = FALSE)
Arguments
include_children |
Logical. Include targets and indicators
nested under each goal? Default |
Value
A list (or data frame) of SDG goals, or NULL when the
service is unreachable.
See Also
sdg_targets(), sdg_indicators(), sdg_data().
Examples
## Not run:
sdg_goals()
sdg_goals(include_children = TRUE)
## End(Not run)
List SDG Indicators
Description
Fetches the list of SDG indicators from the UN SDG API.
Usage
sdg_indicators()
Value
A list (or data frame) of SDG indicators, or NULL
when the service is unreachable.
See Also
Examples
## Not run:
sdg_indicators()
## End(Not run)
List SDG Targets
Description
Fetches the list of SDG targets from the UN SDG API.
Usage
sdg_targets(include_children = FALSE)
Arguments
include_children |
Logical. Include indicators nested under
each target? Default |
Value
A list (or data frame) of SDG targets, or NULL when
the service is unreachable.
See Also
sdg_goals(), sdg_indicators().
Examples
## Not run:
sdg_targets()
## End(Not run)
DSIR ggplot2 Theme
Description
A clean, publication-ready ggplot2 theme based on
ggplot2::theme_minimal() with a consistent color accent and
bordered panels.
Usage
theme_dsi(
base_size = 12,
base_family = "",
color = "steelblue",
grid_color = "grey85"
)
Arguments
base_size |
Base font size in points. Default |
base_family |
Base font family. Default |
color |
Accent color for text and panel borders.
Default |
grid_color |
Color for major grid lines. Default |
Details
The default base_family = "" uses the graphics device's default
font so the theme works on any system (including CRAN's Linux test
machines). For the original DSIR look, pass
base_family = "Cambria" on a system where that font is
installed and registered with R (see grDevices::postscriptFonts()
or the systemfonts package).
Value
A ggplot2 theme object that can be added to a plot with
+.
Examples
library(ggplot2)
ggplot(women, aes(height, weight)) +
geom_point(color = "steelblue") +
theme_dsi()
WPRO Member States (ISO 3166-1 alpha-3)
Description
A character vector of ISO3 codes for countries and areas in the WHO Western Pacific Region.
Usage
wpro_cty
Format
A character vector of length N.