Learn R Programming

pvsR (version 0.3)

getAllBios: Get several candidates' biographical information

Description

This function is essentially a wrapper around CandidateBio.getBio() specified for large amount of requests.

Usage

getAllBios(candidateId, batchsize=100, pause=0, backupfile="bios.list.Rdata")

Arguments

candidateId
a character string or list of character strings with the candidate ID(s) (see references for details)
batchsize
numerical, indicating how many candidateIds should be processed in one batch (defaults to 100).
pause
numerical, indicating how long (in seconds) the download process should be paused after each batch (defaults to 0)
backupfile
character string for the path/file-name of the Rdata-file where the data should be saved (batch-wise) during the download process (default: "bios.list.Rdata").

Value

  • A data frame with a row for each candidate and columns with the following variables describing the candidate: bio.candidate.crpId (OpenSecrets ID), bio.candidate.firstName, bio.candidate.nickName, bio.candidate.middleName, bio.candidate.lastName, bio.candidate.suffix, bio.candidate.birthDate, bio.candidate.birthPlace, bio.candidate.pronunciation, bio.candidate.gender, bio.candidate.family, bio.candidate.photo, bio.candidate.homeCity, bio.candidate.homeState, bio.candidate.education, bio.candidate.profession, bio.candidate.political, bio.candidate.religion, bio.candidate.congMembership, bio.candidate.orgMembership, bio.candidate.specialMsg, bio.office.parties, bio.office.title, bio.office.shortTitle, bio.office.name, bio.office.type, bio.office.status, bio.office.firstElect, bio.office.lastElect, bio.office.nextElect, bio.office.termStart, bio.office.termEnd, bio.office.district, bio.office.districtId, bio.office.stateId, bio.office.committee*.committeeId, bio.office.committee*.committeeName, bio.election*.office, bio.election*.officeId, bio.election*.officeType, bio.election*.parties, bio.election*.district, bio.election*.districtId, bio.election*.status, bio.election*.ballotName.

Details

This functions splits large requests into several batches. The requests are then processed batch-wise and are saved on the local disc to make sure that not too much RAM is assigned to the pvsR task.

References

http://api.votesmart.org/docs/CandidateBio.html Use Candidates.getByOfficeState(), Candidates.getByOfficeTypeState(), Candidates.getByLastname(), Candidates.getByLevenshtein(), Candidates.getByElection(), Candidates.getByDistrict() or Candidates.getByZip() to get a list of candidate IDs.

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 all officials of a certain state
officials <- Officials.getStatewide("FL")
# get all biographical information on those officials
bios <- getAllBios(officials$candidateId[1:100], batchsize=20)
head(bios)

Run the code above in your browser using DataLab