Geocode Steam country codes, state codes, and cityIDs. Can be used to geocode the output of functions that return loccountrycode, locstatecode, or loccityid. This includes functions such as get_player_summary.

Since users are not obliged to specify any level of location, the geocoder skips NA values or falls back to the next higher level, e.g. if city_id is NA, then the state coordinates are returned. This behavior can be suppressed by passing the force_level argument. This can be useful, if the coarseness of the data should be consistent.

This function is powered by quer's Steam location dataset.

geocode_steam(
  country_code,
  state_code = NULL,
  city_id = NULL,
  force_level = NULL,
  cache = TRUE
)

Arguments

country_code

A vector of Steam users' states of residence. Must be an ISO 3166 country code.

state_code

A vector of Steam users' states of residence. Must be a code as returned by the Steam API.

city_id

A vector of Steam users' cities of residence. Must be a code as returned by the Steam API.

force_level

Geographic level that the output must return. Can be one of country, state, and city. If an input location is not available at the specified level, an empty geometry or NA is returned. If NULL, falls back to the next higher level if an input location is unavailable.

cache

The download of Steam location geocodes can take a few seconds. If TRUE, caches this data in a temporary file to speed up subsequent function calls.

Value

If sf is installed, an sf dataframe containing the point geometries of a user location. Otherwise, a dataframe containing lng and lat columns.

Examples

if (FALSE) { # \dontrun{
# get data containing user locations
user <- get_player_summary(c("76561197984981409", "76561197968282875"))
cc <- user$loccountrycode
sc <- user$locstatecode
ci <- user$loccityid

# geocode the user location
geocode_steam(cc, sc, ci)

# force level to state level -- although cityIDs are available
# this can be useful to keep geographic levels consistent
geocode_steam(cc, sc, ci, force_level = "state")

# similarly, if location information is missing but a certain level
# is requested, geocoder returns NA to adhere to the level target
geocode_steam(cc, force_level = "state")
} # }