## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
has_ggplot <- requireNamespace("ggplot2", quietly = TRUE)

## -----------------------------------------------------------------------------
library(unscvetoes)

## -----------------------------------------------------------------------------
nrow(vetoes)
vetoes[vetoes$year == 2026, c("veto_id", "date", "vetoed_by", "topic")]

## -----------------------------------------------------------------------------
table(vetoes$vetoed_item)

## -----------------------------------------------------------------------------
subset(veto_votes, draft_symbol == "S/2024/302", c(member, permanent, vote, veto))

## -----------------------------------------------------------------------------
head(veto_countries[c("date", "country", "iso3c", "cown", "gwno", "vetoed_by")])

## -----------------------------------------------------------------------------
cat(vetoes$context[vetoes$veto_id == 254])

## -----------------------------------------------------------------------------
count_vetoes("member")
count_vetoes("member", from = 1990)

## ----fig.width = 7.2, fig.height = 2.8, eval = has_ggplot---------------------
plot_vetoes(title = NULL)

## -----------------------------------------------------------------------------
by_member <- count_vetoes(c("year", "member"))
by_member$decade <- by_member$year %/% 10 * 10
xtabs(n ~ decade + member, data = by_member)

## -----------------------------------------------------------------------------
sort(table(vetoes$issue_area), decreasing = TRUE)
with(vetoes, table(issue_area, period = ifelse(year < 1990, "1946-89", "1990-2026")))

## -----------------------------------------------------------------------------
with_veto <- subset(veto_votes, vote == "no" & !permanent)
head(sort(table(with_veto$member), decreasing = TRUE), 10)

## -----------------------------------------------------------------------------
recent <- subset(vetoes, year >= 1990)
table(recent$vote_yes)
round(tapply(recent$vote_yes, recent$vetoed_by, mean), 1)

## -----------------------------------------------------------------------------
cy <- veto_country_year()
head(cy)

panel <- expand.grid(cown = c(652, 666, 369), year = 2010:2024)
panel <- merge(panel, cy[c("cown", "year", "n_vetoes")], by = c("cown", "year"), all.x = TRUE)
panel$n_vetoes[is.na(panel$n_vetoes)] <- 0
xtabs(n_vetoes ~ year + cown, data = panel)

## ----eval = FALSE-------------------------------------------------------------
# tmp <- tempfile(fileext = ".zip")
# download.file("https://ucdp.uu.se/downloads/ucdpprio/ucdp-prio-acd-261-csv.zip", tmp)
# acd <- read.csv(unz(tmp, "UcdpPrioConflict_v26_1.csv"))
# 
# v <- subset(vetoes, !is.na(ucdp_conflict_id))
# v$n_vetoes <- 1
# vy <- aggregate(n_vetoes ~ ucdp_conflict_id + year, data = v, FUN = sum)
# names(vy)[1] <- "conflict_id"
# 
# acd_v <- merge(acd, vy, by = c("conflict_id", "year"), all.x = TRUE)
# acd_v$n_vetoes[is.na(acd_v$n_vetoes)] <- 0
# table(intensity = acd_v$intensity_level, veto = acd_v$n_vetoes > 0)

## -----------------------------------------------------------------------------
head(sort(table(vetoes$ucdp_conflict_id), decreasing = TRUE))

## -----------------------------------------------------------------------------
vetoes[vetoes$veto_id == 259, c("draft_symbol", "meeting_record", "meeting_number")]

