LOCAL <- identical(Sys.getenv("LOCAL"), "true") knitr::opts_chunk$set(purl = LOCAL)
RDota2 is an R Steam API client for Valve's game Dota2.
In order to use the package you will need to have a Steam Key which you can get from Steam Community. You will also need a Steam account in order to request a key.
The typical workflow of RDota2 would include registering a key on R and then using the get_* family functions to access the API.
The typical way of working with RDota2 is to register a key on R (once in every section) and then that key will automatically be used within each one of the get_* family functions.
In order to register a key on R you need to use the key_actions
function in the following way:
```{R, eval = LOCAL}
library(RDota2)
```{R, eval = FALSE} #register key on R. xxxxxx is the key you received from Steam. key_actions(action = 'register_key', value = 'xxxxxxxx')
Instead of specifying the key on your console / script (where it would be visible to anyone), good practice dictates to save it in an environment variable. This is a very easy to do process and you only need to do it once. The key will always be made easily available in your R sessions after this. In order to store the key in an environment variable you would need to take the next steps (the following procedure has been taken from the appendix of Best practices for writing an API package):
normalizePath("~/")
in the R console. RDota_KEY=xxxxxxxx
, where RDota_KEY will be the name of the R environment variable and xxxxxxxx will be your individual Steam API Key. Make sure the last line in the file is empty (if it isn’t R will silently fail to load the file). If you’re using an editor that shows line numbers, there should be two lines, where the second one is empty.Sys.getenv
.So, the best practice would be to register your key in the following way:
```{R, eval = LOCAL}
key_actions(action = 'register_key', value = Sys.getenv('RDota_KEY'))
heroes <- get_heroes() head(heroes$content)
Each of the `get_*` family functions has a key argument which should only be used if you work with multiple keys. #### Other Key Actions Other key actions include retrieving a key (to make sure it has been set for example) or deleting the key: ```{R, eval = FALSE} #retrieve key key_actions('get_key') #delete key key_actions('delete_key')
The get_* family functions are the functions used to access the API. They map the following API methods:
Dota 2 methods relating to match information:
Dota 2 methods relating to Dota 2 economy:
You can access the Steam API Documentation from this link.
All get_* functions have three common arguments that can be used:
Moreover, all get_* functions will return a dota_api
object that contains 3 elements:
By default when printing a dota_api
object only the content element will be printed on screen.
The above are true for all the get_* functions, so they will not be analysed in detail in the individual function demonstration that follows.
get_league_listing
returns information about Dota TV-supported leagues. The function does not require any
extra arguments and outputs a data.frame with the following columns:
Steam API Documentation: GetLeagueListing
```{R, eval = LOCAL} str(get_league_listing()$content)
### get_live_league_games `get_live_league_games` returns information about the live league games. The function does not require any extra arguments and outputs a list (called games), of which each element is a game. Each game contains the following information (some might be missing for some games): * players: A list of lists containing information about the players. * radiant_team: A list with information about the radiant team. * dire_team: A list with information about the dire team.. * lobby_id: The lobby id. * match_id: The match id. * spectators: The number of spectators. * series_id: The series id. * game_number: The game number. * league_id: The league id. * stream_delay_s: The stream delay in secs. * radiant_series_wins: Radiant series wins. * dire_series_wins: Dire series wins. * series_type: Series type. * league_series_id: The league series id. * league_game_id: The league game id. * stage_name: The name of the stage. * league_tier: League tier. * scoreboard: A huge list containing scoreboard information. Steam API Documentation: [GetLiveLeagueGames](https://wiki.teamfortress.com/wiki/WebAPI/GetLiveLeagueGames) ```{R, eval = FALSE} #information returned about the first game str(get_live_league_games()$content$games[[1]])
```{R, eval = FALSE}
### get_match_details `get_match_details` provides information about the game and the players participating in a specific match. The function requires a `match_id` to be provided. The function ouputs a list which contains information about the players and the match. The first element of the content list contains information about the players. The following details are included: * account_id: The player's account id. * player_slot: A player's slot is returned via an 8-bit unsigned integer. The first bit represent the player's team, false if Radiant and true if dire. The final three bits represent the player's position in that team, from 0-4. * hero_id: The hero id. * item_0: Top-left inventory item. * item_1: Top-center inventory item. * item_2: Top-right inventory item. * item_3: Bottom-left inventory item. * item_4: Bottom-center inventory item. * item_5: Bottom-right inventory item. * kills: Number of times player killed. * deaths: Number of times player died. * assists: Number of assists player achieved. * leaver_status: Integer from 0-6. Check API documentation. * last_hits: Number of last hits. * denies: Number of denies. * level: Hero level at the end of game. * xp_per_min: Xp per minute gained. * hero_damage: Total damage dealt to heroes. * tower_damage: Total damage dealt to towers. * hero_healing: Total health healed on heroes. * gold: Total gold left at the end of game. * gold_spent: Total gold spent. * scaled_hero_damage: Undocumented. Possibly damage after armour. * scaled_tower_damage: Undocumented. * scaled_hero_healing: Undocumented. * ability_upgrades: A list of all abilities in order of upgrade. The rest of the elements of the content list contain information about the match. The following details are included: * radiant_win: Boolean. Whether radiant won or not. * duration: The duration of a game in seconds. * pre_game_duration: The pre game duration. * start_time: Unix Timestamp of when the game began. * match_id: The match's unique id. * match_seq_num: A sequence number. It represents the order matches were recorded. * tower_status_radiant: Tower Status. Check API documentation. * barracks_status_dire: Same as above. cluster: The server cluster (used for downloading replays). * first_blood_time: Time in seconds when the first blood occured. * lobby_type: Type of lobby. * human_players: Number of human players. * leagueid: The league id. * positive_votes: Number of positive votes. * negative_votes: Number of negative votes. * game_mode: Game mode. * flags: Undocumented. * engine: 0 - source1, 1 - source 2. * radiant_score: Undocumented. * dire_score: Undocumented. Steam API Documentation: [GetMatchDetails](https://wiki.teamfortress.com/wiki/WebAPI/GetMatchDetails) ```{R, eval = LOCAL} #match list contains information about both players and the match match_details <- get_match_details(match_id = 2686721815)$content #match_details[[1]] is a list with all the players - usually 10 #match_details[[1]][[1]] is just one of the 10 players str(match_details[[1]][[1]]) #information about the match str(match_details[-1])
get_match_details
provides information about matches according to a number of parameters. The
available parameters are:
The content element of the list contains a list called matches. Each element of matches list is a match. Each match contains the following sections:
Steam API Documentation: GetMatchHistory
```{R, eval = LOCAL}
match_details <- get_match_history(matches_requested = 2, date_min = '2015-01-01 16:00:00', hero_id = 1)$content
str(match_details[[1]][[1]])
### get_match_history_by_sequence_num `get_match_history_by_sequence_num` provides information about matches ordered by a sequence number. The function can get `start_at_match_seq_num` and `matches_requested` as arguments but both are optional. The function returns a list called matches. Each match follows exactly the same structure as the match retrieved from `get_match_details`. Please see that function for the exact details. Steam API Documentation: [GetMatchHistoryBySequenceNum](https://wiki.teamfortress.com/wiki/WebAPI/GetMatchHistoryBySequenceNum) ```{R, eval = LOCAL} #get 1 match (out of 2) - match_seq_nums are 250 and 251 str(get_match_history_by_sequence_num(matches_requested = 2, start_at_match_seq_num = 250)$content$matches[[1]])
get_scheduled_league_games
returns a list of scheduled league games coming up. The function can
get two optional arguments date_min
and date_max
specifying the time period in which to get the
games. The function returns a list called games. Each game contains the following sections:
Steam API DOcumentation GetScheduledLeagueGames
```{R, eval = LOCAL}
str(get_scheduled_league_games()$content)
### get_team_info_by_team_id `get_team_info_by_team_id` provides informationa about a team given a team id. The function can get two optional arguments. `start_at_team_id` specifies the team id to start returning results from and `teams_requested` specifies the number of teams to return. The function returns a teams list of which each element is a match. The following information for each match is provided: * name: Team's name. * tag: The team's tag. * time_created: Unix timestamp of when the team was created. * calibration_games_remaining: : Undocumented (possibly number of games until a ranking score can be dedided). * logo: The UGC id for the team logo. * logo_sponsor: The UGC id for the team sponsor logo. * country_code: The team's ISO 3166-1 country-code. * url: Team's url which they provided. * games_played: Number of games played. * player_\*_account_id: Player's account id. Will be as many columns as players. * admin_account_id: Team's admin id. * league_id_\*: Undocumented (Probably leagues they participated in). Will be as many columns as leagues. * series_type: Series type. * league_series_id: The league series id. * league_game_id: The league game id. * stage_name: The name of the stage. * league_tier: League tier. * scoreboard: A huge list containing scoreboard information. Steam API Documentation: [GetTeamInfoByTeamID](https://wiki.teamfortress.com/wiki/WebAPI/GetTeamInfoByTeamID) ```{R, eval = LOCAL} #information about one team str(get_team_info_by_team_id()$content$teams[[1]])
get_tournament_player_stats
provides information about tournament players' stats. It requires an
account_id
and optionally a league_id
(only the international is supported i.e. 65006), a
hero_id
or a time_frame
(this is not functional just yet according to the Steam API
Documentation). The function returns a list that contains information about the matches the player
played and information about global stats.
Steam API Documentation: GetTournamentPlayerStats
```{R, eval = LOCAL}
str(get_tournament_player_stats(account_id = 89550641, league_id = 65006)$content)
### get_top_live_game `get_top_live_game` returns the top live games by MMR. It requires a `partner` parameter (not optional) but the API documentation does not specify what it actually is. Values of 1 or 2 or 3 seem to be working. The function returns a `games_list` list which contains information about the top live games. The following categories are returns for each game. They are not documented on the API: * activate_time * deactivate_time * server_steam_id * lobby_id * league_id * lobby_type * game_time * delay * spectators * game_mode * average_mmr * sort_score * last_update_time * radiant_lead * radiant_score * dire_score * players * building_state Steam API Documentation: [GetTopLiveGame](https://wiki.teamfortress.com/wiki/WebAPI/GetTopLiveGame) ```{R, eval = LOCAL} #information about one team str(get_top_live_game(partner = 1)$content$game_list[[1]])
get_game_items
returns information about Dota's items. The function does not require any
extra arguments and outputs a data.frame with the following columns:
Steam API Documentation: GetGameItems
```{R, eval = LOCAL} str(get_game_items()$content)
### get_heroes `get_heroes` returns information about Dota's heroes. The function does not require any extra arguments and outputs a data.frame with the following columns: * name: Hero's name. * id: Hero's ID. * localized_name: Name of the hero in-game. Steam API Documentation: [GetHeroes](https://wiki.teamfortress.com/wiki/WebAPI/GetHeroes) ```{R, eval = LOCAL} str(get_heroes()$content)
get_rarities
returns information about Dota's item rarities. The function does not require any
extra arguments and outputs a data.frame with the following columns:
Steam API Documentation: GetRarities
```{R, eval = LOCAL} get_rarities()$content
### get_tournament_prize_pool `get_tournament_prize_pool` returns information about Dota's tournament prizes. The function can take an optional `leagueid` argument (the league id to get the prize for) and outputs a data.frame with the following columns: * prize_pool: The prize pool. * league_id: The league's id. Steam API Documentation: [GetTournamentPrizePool](https://wiki.teamfortress.com/wiki/WebAPI/GetTournamentPrizePool) ```{R, eval = LOCAL} str(get_tournament_prize_pool()$content)
get_event_stats_for_account
returns an account's event stats. The function takes two arguments. An
eventid
argument (the league id) and an accountid
argument (account id to get stats for). A list
will be returned but the contents of it are not documented in the Steam API Documentation. The function
returns a list that contains:
Steam API Documentation: GetEventStatsForAccount
{R, eval = LOCAL}
get_event_stats_for_account(eventid = 65006, accountid = 89550641)$content
get_item_icon_path
returns the icon path for an item. It requires an iconname
(The item icon name)
and an icontype
(the type of image - 0 is normal, 1 is large and 3 is ingame) argument. There is no
documentation regarding this method in the Steam API Documentation at the time of writing.
Steam API Documentation: GetItemIconPath
If you would like to make any recommendations or give feedback or report a bug please visit the development site on github.
You made it to the end of the documentation! Thanks for reading!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.