---
title: "UN Security Council vetoes in R"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{UN Security Council vetoes in R}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

The package holds a dataset of every veto cast in the UN Security Council from 1946 to October 2026. This vignette shows what is in it, how to count vetoes, how to use the roll calls, and how to join the data to country-year and conflict-year panels.

```{r}
library(unscvetoes)
```

## The data

There are three tables. `vetoes` has one row per vetoed draft. A draft vetoed by two members, such as China and Russia, is one row; this follows the UN's own count.

```{r}
nrow(vetoes)
vetoes[vetoes$year == 2026, c("veto_id", "date", "vetoed_by", "topic")]
```

Most vetoes fell on draft resolutions. In the early years the Council also voted on parts of drafts, on amendments, on membership applications and on whether a question was procedural. `vetoed_item` records which.

```{r}
table(vetoes$vetoed_item)
```

`veto_votes` holds the roll call: one row per Council member per draft, 11 members until 1965 and 15 since. Here is the vote on the 2024 draft on weapons in outer space.

```{r}
subset(veto_votes, draft_symbol == "S/2024/302", c(member, permanent, vote, veto))
```

`veto_countries` has one row per country a draft concerns, with ISO3, Correlates of War and Gleditsch–Ward codes as they stood on the date of the vote.

```{r}
head(veto_countries[c("date", "country", "iso3c", "cown", "gwno", "vetoed_by")])
```

Each draft also carries a short account of what it would have done, the reason the vetoing member gave, and what followed.

```{r}
cat(vetoes$context[vetoes$veto_id == 254])
```

## Counting vetoes

`count_vetoes()` counts drafts by year, or member vetoes by member. A joint veto counts once in a yearly count and once for each member in a count by member.

```{r}
count_vetoes("member")
count_vetoes("member", from = 1990)
```

The plot has one square per member veto. It shows the Soviet vetoes of the late 1940s and 1950s, the American vetoes of the 1970s and 1980s, and the rise since 2011.

```{r, fig.width = 7.2, fig.height = 2.8, eval = has_ggplot}
plot_vetoes(title = NULL)
```

By decade and member:

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

## What the vetoes were about

Region and issue area are coded for every draft, one code each. The issue area follows a fixed order of precedence set out in the codebook.

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

## Using the roll calls

A veto is cast by a permanent member, but elected members sometimes vote with it. These are the elected members that most often voted against a draft that a permanent member vetoed:

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

The number of votes in favour of a vetoed draft gives a rough measure of how isolated the vetoing member was. Since 1990:

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

## Joining country-year data

`veto_country_year()` collapses the country table to one row per country and year. Join it to any panel keyed on COW or Gleditsch–Ward codes, and set years without a veto to zero.

```{r}
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)
```

Palestine, Western Sahara and a few historical entities have no COW or Gleditsch–Ward code. Join on `iso3c` if you need them.

## Joining UCDP conflict-year data

Drafts about an armed conflict have a UCDP conflict identifier, `ucdp_conflict_id`. The code below joins vetoes to the UCDP/PRIO Armed Conflict Dataset, which you download from UCDP.

```{r, 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)
```

Two cautions. Drafts with `ucdp_match == "past"` concern a mission or settlement after a conflict ended, such as the UN force in Cyprus, so they have no active conflict-year to join. Vetoes after 2025 fall outside UCDP version 26.1.

The conflicts with the most vetoes:

```{r}
head(sort(table(vetoes$ucdp_conflict_id), decreasing = TRUE))
```

## Joining UN documents

`draft_symbol`, `meeting_record` and `meeting_number` follow UN style (`S/2023/970`, `S/PV.9499`). They join to UN Digital Library voting records and to resolution data that keep the symbol. For parts of drafts and amendments, `draft_symbol` gives the document voted on and `draft_note` says which part.

```{r}
vetoes[vetoes$veto_id == 259, c("draft_symbol", "meeting_record", "meeting_number")]
```

## Citation

Lundgren, Magnus. 2026. *UN Security Council Vetoes Dataset*. Version 1. University of Gothenburg. Cite a single veto by its `veto_id`.
