Candidates.getByDistrict: Get a list of candidates according to the district they...

Description Usage Arguments Value Author(s) References Examples

Description

This function is a wrapper for the Candidates.getByDistrict() method of the PVS API Candidates class which grabs a list of candidates according to the district they represent for each district and election year. The function sends a request with this method to the PVS API for all district IDs and election years given as a function input, extracts the XML values from the returned XML file(s) and returns them arranged in one data frame.

Usage

1
Candidates.getByDistrict(districtId, electionYear=NULL)

Arguments

districtId

a character string or list of character strings with the district ID(s) (see references for details)

electionYear

(optional) a character string or list of character strings with the election year(s) (Default: >= current year)

Value

A data frame with a row for each candidate and year and columns with the following variables describing the candidate:
candidateList.candidate*.candidateId,
candidateList.candidate*.firstName,
candidateList.candidate*.nickName,
candidateList.candidate*.middleName,
candidateList.candidate*.preferredName,
candidateList.candidate*.lastName,
candidateList.candidate*.suffix,
candidateList.candidate*.title,
candidateList.candidate*.ballotName,
candidateList.candidate*.electionParties,
candidateList.candidate*.electionStatus,
candidateList.candidate*.electionStage,
candidateList.candidate*.electionDistrictId,
candidateList.candidate*.electionDistrictName,
candidateList.candidate*.electionOffice,
candidateList.candidate*.electionOfficeId,
candidateList.candidate*.electionStateId,
candidateList.candidate*.electionOfficeTypeId,
candidateList.candidate*.electionYear,
candidateList.candidate*.electionSpecial,
candidateList.candidate*.electionDate,
candidateList.candidate*.officeParties,
candidateList.candidate*.officeStatus,
candidateList.candidate*.officeDistrictId,
candidateList.candidate*.officeDistrictName,
candidateList.candidate*.officeStateId,
candidateList.candidate*.officeId,
candidateList.candidate*.officeName,
candidateList.candidate*.officeTypeId,
candidateList.candidate*.runningMateId,
candidateList.candidate*.runningMateName.

Author(s)

Ulrich Matter <ulrich.matter-at-unibas.ch>

References

http://api.votesmart.org/docs/Candidates.html
Use District.getByOfficeState() or District.getByZip() to get a list of district ID(s).
See also: Matter U, Stutzer A (2015) pvsR: An Open Source Interface to Big Data on the American Political Sphere. PLoS ONE 10(7): e0130501. doi: 10.1371/journal.pone.0130501

Examples

1
2
3
4
5
6
# First, make sure your personal PVS API key is saved as an option
# (options("pvs.key" = "yourkey")) or in the pvs.key variable:
## Not run: pvs.key <- "yourkey"
# get a list of candidates of certain districts
## Not run: district <- Candidates.getByDistrict(list(25157,25155),2012)
## Not run: district

umatter/pvsR documentation built on Jan. 9, 2021, 4:35 p.m.