Skip to contents

Introduction

unhcrreports automates the creation of humanitarian data reports by combining: 1. Data & Plots: Using unhcrviz and refugees data. 2. AI Analysis: Using LLMs (OpenAI, Azure, local models) to interpret plots. 3. Quarto: To render beautiful, interactive or static HTML/PDF reports.

Setup

1. Installation

# Install from GitHub
remotes::install_github("matheus-hardt/unhcrreports")

2. API Keys

To enable AI analysis, you need to set up API keys in your environment (e.g., .Renviron).

OpenAI:

Sys.setenv(OPENAI_API_KEY = "sk-...")

Azure OpenAI:

Sys.setenv(
  AZURE_OPENAI_ENDPOINT = "https://your-resource.openai.azure.com/",
  AZURE_OPENAI_API_KEY = "your-key",
  AZURE_OPENAI_API_VERSION = "2023-05-15"
)

Generate a Report

The main function is generate_report(). It can create a report for a specific country or region.

Country Report

library(unhcrreports)

# Generate a report for Brazil (BRA) for 2024
# Returns the path to the generated HTML file
report_path <- generate_report(
  type = "country", 
  name = "BRA", 
  year = 2024,
  gp_provider = "openai", # or "azure", "ollama"
  gp_model = "gpt-4o-mini"
)

Region Report

# Generate a report for The Americas
report_path <- generate_report(
  type = "region", 
  name = "The Americas", 
  year = 2024
)

Country Report