Skip to content

Instantly share code, notes, and snippets.

View dickoa's full-sized avatar

Ahmadou Dicko dickoa

View GitHub Profile
@dickoa
dickoa / beginner_intro.R
Created August 29, 2024 07:15
Intro R code to copy
library(tidyverse) # copy this part only if you don't have it yet
pop <- tibble(year = rep(2023, 5),
coa = c("Sudan", "Burkina Faso", "DRC", "Syria", "Yemen"),
pop = c(47.5, 22.9, 103.2, 22.1, 33.7),
idp = c(9.1, 2.3, 6.3, 7.2, 4.5))
@dickoa
dickoa / dtm_api_test.R
Created June 21, 2024 17:15
Pull DTM data from API using R and httr2
library(tidyverse)
library(httr2)
library(cli)
url <- 'https://dtmapi.iom.int/api/IdpAdmin2Data/GetAdmin2Data'
payload <- list(operation = "",
countryName = "Afghanistan",
admin0Pcode = "",
reportingDate = list(fromDate = "2018-12-31", toDate = "2023-05-31"),
@dickoa
dickoa / up_brewer.R
Last active August 27, 2023 16:31
Brewer method unequal probabilities speed up
up_brewer <- function(pik, eps = 1e-06) {
if (any(is.na(pik)))
stop("there are missing values in the pik vector")
list <- pik > eps & pik < 1 - eps
pikb <- pik[list]
s <- pik
N <- as.integer(length(pikb))
sb <- vector(mode = "double", length = N)
r <- .C("C_up_brewer", pikb, N, result = sb)
s[list] <- r$result
@dickoa
dickoa / pbs_moe_chart.R
Created February 24, 2023 23:06
Reproduce (kind of) PBS poll charts with MoE
library(tidyverse)
library(ggpattern)
library(ggtext)
## https://www.pbs.org/newshour/politics/most-americans-want-congress-to-compromise-as-debt-ceiling-looms
## Great chart by Megan McGrew
col <- c("#2aa7ff", "#f93037", "#a44bd2", "#c0c1c0")
bg_col <- "#ecedec"
@dickoa
dickoa / ridl_regional_dataset_list.R
Created February 10, 2023 15:52
List of dataset per region in RIDL including year of creation of each dataset
library(tidyverse)
library(ridl)
library(lubridate)
### Targeted region
region <- "west-and-central-africa"
### List all containers
ct_nm <- rc_list()
@dickoa
dickoa / onedriveR.R
Created April 6, 2022 09:56
Download and read Excel sheets from R
library(Microsoft365R)
library(tidyverse)
library(readxl)
odb <- get_business_onedrive(app = "d44a05d5-c6a5-4bbb-82d2-443123722380")
### Check files
odb$list_items()
### Check files in "Documents"
@dickoa
dickoa / get_ridl_metadata_wca.R
Created February 21, 2022 19:02
Get the list of RIDL Datasets for West and Central Africa
library(tidyverse)
library(janitor)
library(ridl) ## remotes::install_gitlab("dickoa/ridl")
library(popdata) ## remotes::install_gitlab("dickoa/popdata")
### Get the list of countries name, iso3 and unhcr code
ct <- pd_countries
ct <- filter(pd_countries,
bureau == "West and Central Africa") |>
@dickoa
dickoa / mali_violence_acled.R
Last active February 20, 2022 19:06
Mali violence map ACLED
library(tidyverse)
library(sf)
library(rgeoboundaries) ## remotes::install_github("wmgeolabs/rgeoboundaries")
library(racled) ## remotes::install_gitlab("dickoa/racled")
library(cowplot)
### Get Mali country boundaries
mli_adm0 <- gb_adm0("mali")
### Get Mali ACLED data
@dickoa
dickoa / read_kobo_data.R
Created February 18, 2022 09:28
Read KoBoToolbox data
library(robotoolbox) # if not available please do remotes::install_gitlab("dickoa/robotoolbox")
library(dplyr)
library(labelled)
token <- kobo_token(username = "xxxx",
password = "xxxxx",
url = "kobo.humanitarianresponse.info")
kobo_setup(url = "kobo.humanitarianresponse.info",
token = token)
@dickoa
dickoa / blastula_o365.R
Created February 1, 2022 14:17
Sending email from R using Microsoft365R
library(Microsoft365R)
library(blastula)
outl <- get_business_outlook(app = "d44a05d5-c6a5-4bbb-82d2-443123722380") ## just once after you can do `outl <- get_business_outlook()`
body <- "## Hello!
This is an email message that was generated by the blastula package.
We can use **Markdown** formatting with the `md()` function.