Learn R Programming

pvsR (version 0.3)

getAllVotes: Get several votes

Description

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

Usage

getAllVotes(actionId, batchsize=100, pause=0, backupfile="votes.list.Rdata")

Arguments

actionId
a character string or list of character strings with the action ID(s) (see references for details)
batchsize
numerical, indicating how many actionIds 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: "votes.list.Rdata").

Value

  • A data frame with a row for each vote and columns with the following variables describing the vote: votes.vote*.candidateId, votes.vote*.candidateName, votes.vote*.officeParties, votes.vote*.action.

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/Votes.html Use Votes.getBill() or Votes.getByOfficial() to get a list of action 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
bill <- Votes.getBill("17623", separate=c("actions", "sponsors"))
actionids <- bill$actions$actionId
# get all votes on this acti
votes <- getAllVotes(actionids, batchsize=2)
head(votes)

Run the code above in your browser using DataLab