---
title: "AlgeriAPIs: Access Algerian Data via Public APIs"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{AlgeriAPIs: Access Algerian Data via Public APIs}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(AlgeriAPIs)
library(ggplot2)
library(dplyr)
```

# Introduction

The `AlgeriAPIs` package provides a unified interface to access open data from the **World Bank API** and the **REST Countries API**, with a focus on **Algeria**. It allows users to retrieve real-time or historical information on topics such as economic indicators, population statistics, and key geopolitical details.

`AlgeriAPIs` enables users to query data in a reproducible way and is designed for researchers, analysts, and developers who require reliable and programmatic access to Algerian data through established APIs. 

## Functions for AlgeriAPIs

The `AlgeriAPIs` package provides several core functions to access real-time and structured information about **Algeria** from public APIs such as the **World Bank API** and the **REST Countries API**.

Below is a list of the main functions included in the package:

- `get_algeria_child_mortality()`: Get Algeria’s Under-5 Mortality Rate data from the World Bank.

- `get_algeria_cpi()`: Get Algeria’s Consumer Price Index (2010 = 100) data from the World Bank.

- `get_algeria_energy_use()`: Get Algeria’s Energy Use (kg of oil equivalent per capita) data from the World Bank.

- `get_algeria_gdp()`: Get Algeria’s GDP (current US$) data from the World Bank.

- `get_algeria_holidays()`: Get official public holidays in Algeria for a given year, e.g., `get_algeria_holidays(2025)`.

- `get_algeria_hospital_beds()`: Get Algeria’s Hospital Beds (per 1,000 people) data from the World Bank.

- `get_algeria_literacy_rate()`: Get Algeria’s Adult Literacy Rate data from the World Bank.

- `get_algeria_life_expectancy()`: Get Algeria’s Life Expectancy at Birth data from the World Bank.

- `get_algeria_population()`: Get Algeria’s Total Population data from the World Bank.

- `get_algeria_unemployment()`: Get Algeria’s Total Unemployment Rate data from the World Bank.

- `get_country_info_dz()`: Get key country information for Algeria.

- `view_datasets_AlgeriAPIs()`: View available curated datasets included in AlgeriAPIs.

These functions allow users to access high-quality and structured information on **Algeria**, which can be combined with tools like **dplyr** and **ggplot2** to support a wide range of data analysis, visualization, and research tasks. In the following sections, you’ll find examples on how to work with `AlgeriAPIs` in practical scenarios.

### Algeria's GDP (Current US$) from World Bank 2022 - 2017

```{r algeria-gdp,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}


algeria_gdp <- head(get_algeria_gdp())

print(algeria_gdp)

```


### Algeria's Life Expectancy at Birth from World Bank 2022 - 2017

```{r algeria-life-expectancy,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}

algeria_life_expectancy <- head(get_algeria_life_expectancy())

print(algeria_life_expectancy)

```


### Algeria's Total Population from World Bank 2022 - 2017

```{r algeria-population,echo = TRUE,message = FALSE,warning = FALSE,results = 'markup'}

algeria_population <- head(get_algeria_population())

print(algeria_population)

```

## Internet Users (% of Population) Over Time

```{r algeria-plot, message=FALSE, warning=FALSE, fig.width=7, fig.height=5}

# Simple line plot using only ggplot2 and dplyr
ggplot(internet_users_tbl_df, aes(x = Year)) +
  geom_line(aes(y = Algeria, color = "Algeria"), size = 1.2) +
  geom_line(aes(y = Maghreb_union, color = "Maghreb Union"), size = 1.2) +
  geom_line(aes(y = Arab_world, color = "Arab World"), size = 1.2) +
  geom_line(aes(y = European_Union, color = "European Union"), size = 1.2) +
  geom_line(aes(y = The_World, color = "The World"), size = 1.2) +
  labs(
    title = "Internet Users (% of Population) Over Time",
    subtitle = "Comparison between Algeria and other regions",
    x = "Year",
    y = "Internet Users (%)",
    color = "Region"
  ) +
  theme_minimal() +
  theme(
    plot.title = element_text(face = "bold", size = 16),
    plot.subtitle = element_text(size = 12),
    axis.title = element_text(size = 12),
    legend.position = "bottom"
  )


```


## Dataset Suffixes

Each dataset in `AlgeriAPIs` is labeled with a *suffix* to indicate its structure and type:

- `_df`: A standard data frame.

- `_tbl_df`: A tibble data frame object.


## Datasets Included in AlgeriAPIs

In addition to API access functions, `AlgeriAPIs` offers curated open datasets focused on **Algeria**, with only two datasets included in this first version (`algiers_temp_df` and `internet_users_tbl_df`), and many more to be added in future updates.

Below are some featured examples:

- **algiers_temp_df**: A data frame containing daily maximum and minimum air temperature records for Algiers, Algeria.

- **internet_users_tbl_df**: A tibble containing the percentage of Internet users in Algeria and comparative data for regional and global contexts.


## Conclusion

The `AlgeriAPIs` package provides a reliable and reproducible way to access data from public RESTful APIs, including the **World Bank API** and the **REST Countries API**, focusing on **Algeria**. It enables users to retrieve real-time or historical information on economic indicators, demographic statistics, and key geopolitical data.

Designed for researchers, analysts, and developers, `AlgeriAPIs` facilitates programmatic access to Algerian data, making it easier to integrate this information into analyses, reports, and applications.

<div class="tocify-extend-page" data-unique="tocify-extend-page" style="height: 0;"></div>
