knitr::opts_chunk$set(echo = TRUE) # Load the package. library(igdb)
The IGDB package provides access to the IGDB API which gives information on video games, developers, reviews, companies, and other related content.
Use devtools to install from Github.
devtools::install_github("detroyejr/igdb")
At the time of this package was developed, most of the available API endpoints are covered. These include:
igdb_characters
: Charactersigdb_collections
: Collectionsigdb_companies
: Companyigdb_credits
: Creditsigdb_franchises
: Franchiseigdb_games
: Gameigdb_genres
: Genreigdb_keywords
: Keywordsigdb_pages
: Pagesigdb_platforms
: Platformigdb_pulses
: Pulseigdb_reviews
: ReviewsEach function follows a similar format.
search
: title or keyword relating to kinds of results you want to return.id
: each element in the api has an associated id. If you know the id of the game, review, or company you can pass that as a single number or vector of numbers to retrieve only those elements.n
: maximum number of results to return.limit
: maximum number of results per page.scroll
: an alternative method for pagination which allows you to request more than 10,000 rows (see pagination).filter
: a method for narrowing search results (e.g "[created_at][gt]=2017-01-01"
) (see filters).fields
: a vector of columns the api should return.order
: a string that sets the order of the results (e.g created_at:asc
, name:desc
)api_key
: an API key provided when you sign up.You can find the full documentation for the API here.
Before you can begin to use the service, sign up and receive an API key. Once you have your key, you can pass it to the function parameter api_key
or use
Sys.setenv("IGDB_KEY" = 'YOUR_API_KEY`)
to add it to your environment. The function igdb_key()
will look in the system environment for a variable with that name.
# Returns games matching "bioshock" but filters games released after 2015. igdb_games( search = "bioshock", order = "first_release_date:asc", filter = "[first_release_date][lt]=2016-01-01", fields = c("id", "name", "first_release_date", "rating", "popularity") )
igdb_companies( search = "2k", order = "start_date:desc", fields = c("id", "name", "start_date", "published"), n = 20 )
igdb_reviews( search = "bioshock", fields = c("username", "created_at", "title", "game", "views", "platform") )
igdb_characters( search = "booker dewitt" )
To get results for specific games, use the filter options.
# Filter on slug value. igdb_games(filter = "[slug][eq] = bioshock-infinite") # Filter on game id. igdb_reviews(filter = "[game][eq] = 538")
In some cases if there are no results, the API will issue a 404 reponse causing a function error.
igdb_genres(search = "action")
Scrolling may also not work always work as expected with smaller queries. We still get the first 50 results, but not as many as expected. R will issue a warning when this happens. For better results, switch to pagination using offset.
# Pagination with Scroll. games <- igdb_games("halo", scroll = TRUE, n = 100) NROW(games) # Pagination with offset. games <- igdb_games("halo", scroll = FALSE, n = 100) NROW(games)
If you find any bugs, you can file an issue or create a pull request. Each function was created using the same basic template. As long as there are no breaking api changes, adding new endpoints should be simple.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.