Learn R Programming

pvsR (version 0.1.1)

Candidates.getByElection: Get a list of candidates according to the election they are running for

Description

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

Usage

Candidates.getByElection(electionId, stageId=NULL)

Arguments

electionId
a character string or list of character strings with the election ID(s) (see references for details)
stageId
(optional) a character string or list of character strings with the stage ID(s) (default: all)

Value

  • A data frame with a row for each candidate and columns with variables describing the candidate. The returned data frame contains a row for each candidate 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

References

http://api.votesmart.org/docs/Candidates.html Use Election.getElectionByYearState() or Election.getElectionByZip() to get election ID(s).

Examples

Run this code
# First, make sure your personal PVS API key is saved as character string in the pvs.key variable:
pvs.key <- "yourkey"
# get a list of candidates for certain election IDs
candidates <- Candidates.getByElection(list(2582,2646))
candidates

Run the code above in your browser using DataLab