Learn R Programming

pvsR (version 0.3)

getAllLocalOfficials: Fetch data on all local (city- or county-) officials

Description

This function is essentially a wrapper around Local.getOfficials().

Usage

getAllLocalOfficials(locality="counties", batchsize=50,
 pause=0, backupfile="locofs.list.Rdata")

Arguments

locality
a character string indicating whether data on county-officials ("counties") or city-officials ("cities") should be downloaded.
batchsize
numerical, indicating the number of requests that should be processed in one batch (defaults to 50).
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: "locofs.list.Rdata").

Value

  • A data frame with a row for each official and columns with the following variables describing the official: candidatelist.candidate*.candidateId, candidatelist.candidate*.firstName, candidatelist.candidate*.nickName, candidatelist.candidate*.middleName, candidatelist.candidate*.lastName, candidatelist.candidate*.suffix, candidatelist.candidate*.title, candidatelist.candidate*.electionParties, candidatelist.candidate*.electionDistrictId, candidatelist.candidate*.electionStateId, candidatelist.candidate*.officeParties, candidatelist.candidate*.officeDistrictId, candidatelist.candidate*.officeDistrictName, candidatelist.candidate*.officeStateId, candidatelist.candidate*.officeId, candidatelist.candidate*.officeName, candidatelist.candidate*.officeTypeId.

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/Local.html Use Local.getCounties() or Local.getCities() to get a list of local 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 a list of all local officials
all_countyofficials <- getAllLocalOfficials()
head(officials)

Run the code above in your browser using DataLab