knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
rpredictit package provides an interface to the PredictIt public API.
In addition to providing a wrapper to retrieve market data, this package includes visualization functions for plotting historical price data and exploring available markets. The package also comes with a demo shiny application for illustrating example use cases.
rpredictit is not affiliated with any predictive markets and is presented for informational purposes only. Always confirm with your own research before making an investment.
License to use data made available via the API is for non-commercial use and PredictIt is the sole source of such data.
Once released, you may install the stable version from CRAN, or the development version using devtools:
# development version, via devtools devtools::install_github('danielkovtun/rpredictit')
To start off, try running a demo Shiny application included with the package by running:
rpredictit::all_markets() to return a tibble containing bid and ask data for all PredictIt markets:
Alternatively, to return an interactive htmlwidget (DT::datatable) table containing HTML formatted market data, pass the returned bid/ask data to
data <- rpredictit::all_markets() rpredictit::markets_table(data)
To plot historical prices, download a 'csv' file for a specific contract from PredictIt's website and pass the file path to
Then, pass in the returned contract data object to
filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv" csv_path <- system.file("extdata", filename, package = "rpredictit") contract_data <- rpredictit::parse_historical_csv(csv_path) rpredictit::historical_plot(contract_data)
If you are only interested in "Tweet count" markets, use
rpredictit::tweet_markets() to return all available "Tweet" markets:
data <- rpredictit::tweet_markets() rpredictit::markets_table(data)
To return data for a specific market, use
id refers to the numerical code pertaining to the market of interest.
You can find a market's numerical code by consulting its URL or by first calling the all markets API (
markets <- rpredictit::all_markets() id <- markets$id rpredictit::single_market(id)
See the full documentation at https://danielkovtun.github.io/rpredictit.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.