Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/votesmartPublic template

💫 R wrapper around the VoteSmart galaxy of data 💫

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

decktools/votesmart

galaxy_gif

checkCRAN status

votesmartdeck

This package is a wrapper around theVoteSmartAPI written by your friendlyneighborhood progressive tech organization, 🌟DeckTechnologies 🌟. Feel free to use this packagein any way you like.

VoteSmart provides information on US political candidates’ positions onissues, votes on bills, and ratings by third party organizations, amongother data.

Installation

install.packages("votesmart")

Or the development version:

devtools::install_github("decktools/votesmart",build_vignettes=TRUE)

API Keys

You’ll need a VoteSmart API key in order to use this package. You canregister for onehere.

Store your key in an environment variable namedVOTESMART_API_KEY with

Sys.setenv(VOTESMART_API_KEY = "<your_key>")

You can check that it’s there with

Sys.getenv("VOTESMART_API_KEY")

This package never stores your key in your R session’s globalenvironment.

An Example

VoteSmart collects ratings on various issues that Special InterestGroups (SIGs) give to political candidates.

Let’s say we want to know how Elizabeth Warren tends to be rated on afew issues.

library(votesmart)suppressPackageStartupMessages(library(dplyr))conflicted::conflict_prefer("filter","dplyr")#> [conflicted] Will prefer dplyr::filter over any other package.

We’ll first want to know what her VoteSmartcandidate_id is. We cansearch for her usingcandidates_get_by_lastname:

warrens<-  candidates_get_by_lastname("warren",election_years=2012  )#> Requesting data for {last_name: warren, election_year: 2012, stage_id: }.knitr::kable(warrens)
candidate_idfirst_namenick_namemiddle_namelast_namesuffixtitleballot_namestage_idelection_yearpreferred_nameelection_partieselection_statuselection_stageelection_district_idelection_district_nameelection_officeelection_office_idelection_state_idelection_office_type_idelection_specialelection_dateoffice_partiesoffice_statusoffice_district_idoffice_district_nameoffice_state_idoffice_idoffice_nameoffice_type_idrunning_mate_idrunning_mate_name
139104AdamNALeeWarrenNANAAdam Lee Warren2012AdamRepublicanLostPrimaryNANAAttorney General12MOSFALSE08/07/2012NANANANANANANANANANA
103860DennisNANAWarrenNANADennis C. Warren2012DennisRepublicanWithdrawnGeneral2844616State Senate9IDLFALSE11/06/2012NANANANANANANANANANA
141272ElizabethNAAnnWarrenNASenatorElizabeth A. Warren2012ElizabethDemocraticWonGeneralNANAU.S. Senate6MACFALSE11/06/2012Democraticactive20512SrMA6U.S. SenateCNANA
117839HarryNAJosephWarrenNARepresentativeHarry Warren2012HarryRepublicanWonGeneral2552077State House8NCLFALSE11/06/2012Republicanactive2551976NC8State HouseLNANA
138202PeteNANAWarrenNANAPete Warren2012PeteRepublicanRemovedPrimary2184230State House8FLLFALSE08/14/2012NANANANANANANANANANA
137066StephenNANAWarrenNANAStephen Warren2012StephenRepublicanLostPrimary2786522BState House8IDLFALSE05/15/2012NANANANANANANANANANA
135832TomNANAWarrenNANATom Warren2012TomDemocraticLostGeneral2578276State House8OHLFALSE11/06/2012NANANANANANANANANANA
139311WesleyNAG.WarrenNANAWesley G. Warren2012WesleyRepublicanLostGeneral2187462State House8FLLFALSE11/06/2012NANANANANANANANANANA

Filtering to her first name and taking hercandidate_id, we can nowgrab Warren’s ratings by all SIGs withrating_get_candidate_ratings.

(id<-warrens %>%  filter(first_name=="Elizabeth") %>%  pull(candidate_id))#> [1] "141272"ratings<-  rating_get_candidate_ratings(candidate_ids=id,  )#> Requesting data for {candidate_id: 141272, sig_id: }.knitr::kable(ratings %>% sample_n(3))
rating_idcandidate_idsig_idratingrating_nametimespanrating_textcategory_id_1category_name_1category_id_2category_name_2category_id_3category_name_3category_id_4category_name_4category_id_5category_name_5category_id_6category_name_6category_id_7category_name_7category_id_8category_name_8category_id_9category_name_9
86151412721161100Positions2014Senator Elizabeth Warren supported the interests of the American Federation of Labor and Congress of Industrial Organizations (AFL-CIO) 100 percent in 2014.43Labor UnionsNANANANANANANANANANANANANANANANA
10219141272241218Lifetime Positions2016Senator Elizabeth Warren supported the interests of the Conservative Review 18 percent in 2016.17ConservativeNANANANANANANANANANANANANANANANA
970514127219851Positions2017-2018Senator Elizabeth Warren supported the interests of the NumbersUSA 1 percent in 2017-2018.40ImmigrationNANANANANANANANANANANANANANANANA

And compute on them:

ratings %>%  filter(category_name_1%in%      c("Environment","Fiscally Conservative","Education","Civil Liberties and Civil Rights","Campaign Finance"      )  ) %>%  group_by(category_name_1) %>%  summarise(avg_rating= mean(as.numeric(rating),na.rm=TRUE)  ) %>%  arrange(category_name_1)#> # A tibble: 5 × 2#>   category_name_1                  avg_rating#>   <chr>                                 <dbl>#> 1 Campaign Finance                     100#> 2 Civil Liberties and Civil Rights      86.6#> 3 Education                             89.3#> 4 Environment                           87.2#> 5 Fiscally Conservative                  8.78

For more in-depth examples of how these all fit together, check out thevignette with:

vignette("votesmart")

Available Functions

These functions are named after thesnake_cased version of the APIendpoints.

If you see an endpoint you want to be made available in this packagethat isn’t yet, feel free to submit anissue or apullrequest!

Summary of Functions

candidates_get_by_lastname

Get a dataframe of candidates given a vector oflast_names,election_years (optional, defaulting to current year), andstage_ids(optional)

candidates_get_by_levenshtein

Get a dataframe of fuzzy-matched candidates given a vector oflast_names,election_years (optional), andstage_ids (optional)

candidates_get_by_office_state

Get a dataframe of candidates by the state in which they ran for officegiven a vector ofstate_ids (optional),office_ids, andelection_years (optional)

election_get_election_by_year_state

Get a dataframe of election ids and their attributes given a vector ofyears andstate_ids (optional)

measure_get_measures

Get a dataframe of ballot measure attributes given ameasure_id

measure_get_measures_by_year_state

Get a dataframe of ballot measure ids and their attributes given avector ofyears andstate_ids (optional)

office_get_levels

Get the VoteSmartoffice_level_ids and their associated names(federal, state, local)

office_get_offices_by_level

Getoffice_ids and their associated names (e.g. "President") for agivenoffice_level_id

rating_get_candidate_ratings

Get SIG (Special Interest Group) ratings for candidates given acandidate_id and asig_id (optional)

rating_get_categories

Get ratingcategory_ids and their associatednames(e.g. "Abortion","Environment") given a vector ofstate_ids(optional)

rating_get_sig

Get information about a vector of SIGs (Special Interest Groups) given asig_id

rating_get_sig_list

Get a dataframe of SIG (Special Interest Group) given a ratingcategory_id and astate_id (optional)

votes_get_by_official

Get a dataframe of the way officials have voted on bills given acandidate_id, anoffice_id (optional), acategory_id (optional)and ayear the vote occurred (optional)

Package Data

Only a subset of all of the VoteSmart endpoints have yet been madeavailable through this package.

You can see a full dataframe of the VoteSmart endpoints and theirassociated arguments with

data("endpoint_input_mapping")

or

data("endpoint_input_mapping_nested")

Other Details

  • This package currently contains no rate limiting infrastructure asthere is very little information about what rate limits VoteSmartimposes, if any

  • The VoteSmart API does not allow for bulk requests, i.e. a singlerequest can only contain one value for each parameter

    • The functions in this package allow multiple inputs to be specifiedfor each argument, but requests are sent one at a time for eachcombination of inputs

Feel free to reach out in theIssues with any bugs orfeature requests! 💫

About

💫 R wrapper around the VoteSmart galaxy of data 💫

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp