get_party_logo: Extract party logo URL from Wikipedia

View source: R/party_logo.R

get_party_logoR Documentation

Description

Extracts the party logo image URL from a political party's English Wikipedia page. The function scrapes the party infobox for the logo image.

Usage

get_party_logo(url)

Arguments

url

A character vector of Wikipedia URLs for political party pages.

Details

The function looks for logo images in the Wikipedia infobox. The returned URL is typically a Wikimedia Commons thumbnail URL. Note that some party pages may not have logos, or the logo may be in a non-standard location.

The returned URLs point to image files hosted on Wikimedia servers. These can be used directly in R graphics or downloaded for further processing.

For use with 'dplyr::mutate()', this function is vectorized over the 'url' argument.

Value

A character vector of logo image URLs (or NA for failed extractions or pages without logos).

Examples


if (curl::has_internet()) {
  # Single party
  get_party_logo("https://en.wikipedia.org/wiki/Democratic_Party_(United_States)")

  # Multiple parties
  urls <- c(
    "https://en.wikipedia.org/wiki/Democratic_Party_(United_States)",
    "https://en.wikipedia.org/wiki/Republican_Party_(United_States)"
  )
  get_party_logo(urls)
}


partycoloR documentation built on Jan. 28, 2026, 1:07 a.m.