Candidates.getByOfficeTypeState: Get a list of candidates according to office type and state...

Description Usage Arguments Value Author(s) References Examples

Description

This function is a wrapper for the Candidates.getByOfficeTypeState() method of the PVS API Candidate class which grabs a list of candidates according to office type and state representation. The function sends a request with this method to the PVS API for all state IDs, office type 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.getByOfficeTypeState(stateId="NA", officeTypeId, electionYear=NULL, all=FALSE)

Arguments

stateId

(optional) a character string or list of character strings with the state ID(s) (default: "NA", for national) (see references for details)

officeTypeId

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

electionYear

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

all

a logical indicator; if TRUE data on all possible combinations of the input variables are returned, if FALSE (default) only the exact combinations of them (see example)

Value

A data frame with 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*.electionofficeTypeId,
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*.officeTypeId,
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 State.getStateIDs() to get a list of state IDs.
See http://api.votesmart.org/docs/semi-static.html or use Office.getTypes() or Office.getOfficesByLevel() to get a list of office types ID(s).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# First, make sure your personal PVS API key is saved as character string in the pvs.key variable:
## Not run: pvs.key <- "yourkey"
# get a data frame of candidates according to all state/officeType/electionYear combinations
## Not run: candidates <- Candidates.getByOfficeTypeState(stateId=list("NJ","NY"),
officeTypeId=list("C","L"), electionYear=list(2012,2008), all=TRUE)
## End(Not run)
## Not run: candidates
# get a data frame of candidates according to the exact state/officeType/electionYear combinations
# (i.e., "NY"/6/2012, "NJ"/7/2008)
## Not run: candidates <- Candidates.getByOfficeTypeState(stateId=list("NJ","NY"),
officeTypeId=list("C","L"), electionYear=list(2012,2008), all=FALSE)
## End(Not run)
## Not run: candidates

pvsR documentation built on May 2, 2019, 5:16 a.m.