Package 'inegiR'

Title: Integrate INEGI’s (Mexican Stats Office) API with R
Description: Provides functions to download and parse information from INEGI (Official Mexican statistics agency). To learn more about the API, see <https://www.inegi.org.mx/servicios/api_indicadores.html>.
Authors: Eduardo Flores
Maintainer: Eduardo Flores <[email protected]>
License: CC0
Version: 3.0.0
Built: 2025-02-18 04:25:46 UTC
Source: https://github.com/eflores89/inegir

Help Index


Integrate INEGI’s (Mexican Stats Office) API with R

Description

Provides functions to download and parse information from INEGI (Official Mexican statistics agency).

Details

Package: inegiR
Type: Package
Version: 2.0
Date: 2018-03-27

Author(s)

Eduardo Flores <[email protected]>

References

The INEGI API can be found here: http://www.inegi.org.mx/desarrolladores/indicadores/apiindicadores.aspx


Extracts INEGI GeoJSON

Description

Helper function

Usage

ext_geo(x)

Arguments

x

GeoJSON description

Value

Data.frame


Gets gas cost from INEGI API

Description

Helper function

Usage

get_gas(token, onlyPremium = FALSE)

Arguments

token

Sakbe API token supplied by INEGI

onlyPremium

Only export premium price

Value

data.frame


Get INEGI Catalogs

Description

Allows you to download the catalogs of frequencies, sources, notes, topics and indicator names. Called in the background in some functions.

Usage

incat_freq(token, id = NULL)

incat_source(token, id = NULL)

incat_notes(token, id = NULL)

incat_topic(token, id = NULL)

incat_indicator(token, id = NULL)

Arguments

token

INEGI API token

id

Optional id. If NULL, will download entire catalog.

Value

data.frame

Author(s)

Eduardo Flores

Examples

# Get the corresponding frequency for frequency id #8 (monthly)
## Not run: 
token <- "webservice token"
incat_freq(token, id = "8")

## End(Not run)
# Get all of the note descriptions
## Not run: 
token <- "webservice token"
incat_notes(token)

## End(Not run)
#' # Get all of the sources descriptions
## Not run: 
token <- "webservice token"
incat_source(token)

## End(Not run)

Obtains the catalog of economic data neumonics

Description

Neumonics are shorthand names for series of economic data, akin to the Fed FRED names. This catalog downloads the neumonic with the indicator code, to easily match with an API call. This catalog is maintained by INEGI.

Usage

incat_neumonics()

Value

data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
catalog <- incat_neumonics()

## End(Not run)

Balance of Payments for Mexico

Description

Returns Current Account revenue, expenses and total and Financial Account total, errors, reservs and adjustments for Mexico.

Usage

inegi_bop(token)

Arguments

token

API token supplied by INEGI

Value

Data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token <- "webservice_token"
balance_of_payments <- inegi_bop(token)

## End(Not run)

Returns DENUE businesses

Description

Returns data.frame with businesses registered in DENUE in the vicinity of supplied coordinates.

Usage

inegi_denue(latitud, longitud, token, meters = 250, keyword = "todos")

Arguments

latitud

Character vector with latitud (in decimals)

longitud

Character vector with longitud (in decimals)

token

API token supplied by INEGI

meters

Meters to search in a circle from coordinates. Defaults to 250

keyword

Keyword to search in business description (in spanish). Defaults to all (todos).

Value

Data.frame

Author(s)

Eduardo Flores

Examples

# All businesses in a 1 km radius from the Macroplaza in Monterrey, Mex.
## Not run: 
token<-"webservice_token"
latitud<- 25.669194
longitud<- -100.30990
businesses <- inegi_denue(latitud, longitud, token, meters = 1000)

## End(Not run)

Find businesses in a grid larger than 5 kms

Description

Returns data.frame with businesses registered in the DENUE in spaces larger than 5 kilometers. Calls make_grid. Functions contributed by Arturo Cardenas https://github.com/arturocm.

Usage

inegi_denue_grid(lat1, lat2, lon1, lon2, token, meters = 5000,
  keyword = "todos", space_lat = 0.07, space_lon = 0.07,
  uniqueonly = TRUE)

Arguments

lat1

First corner (latitud)

lat2

Second corner (latitud)

lon1

First corner (longitud)

lon2

Second corner (longitud)

token

API token supplied by INEGI

meters

Distance in meters to search by coordinate

keyword

Keyword of businesses to include. Defaults to all ("todos")

space_lat

Space between latitud coordinates defaults to 0.07 degrees

space_lon

Space between longitud coordinates defaults to 0.07 degrees

uniqueonly

Default = TRUE, eliminates duplicate businesses

Details

Makes a loop for each pair of coordinates, creating a grid to extract businesses inside. Uses maximum and minimum coordinate pairs to draw frame.

Value

Data.frame

Author(s)

Arturo Cardenas

Examples

## Not run: 
token<-"webservice_token"
latitud1 <- 25.669194
latitud2 <- 25.169194
longitud1 <- -100.30990
longitud2 <- -101.20102
businesses <- inegi_denue_grid(latitud1, latitud2, longitud1, longitud2, token)

## End(Not run)

Returns statistics of coordinate

Description

Returns basic statistics of businesses, using DENUE, in the vecinity of coordinates.

Usage

inegi_denue_stats(latitud_vector, longitud_vector, token, meters = 250,
  keyword = "todos")

Arguments

latitud_vector

number of column in data with latitud column

longitud_vector

number of column in data with longitud column

token

API token supplied by INEGI

meters

Distance in meters to search by coordinate

keyword

Keyword of businesses to include. Defaults to all ("todos")

Details

Some columns, like employee numbers are experimental (the employees are added considering size of company).

Value

Data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token<-"webservice_token"
df <- as.data.frame(latitud  = c(25.669194, 25.121194),
                  longitud = c(-100.30990, -99.81923))
stats <- denue_varios_stats(data     = df,
                          col_lat  = 1,
                          col_long = 2,
                          metros   = 500)

## End(Not run)

Returns INEGI destiny id's with matching searches

Description

Returns data.frame with id's and coordinates that match with the API names.

Usage

inegi_destiny(search, token)

Arguments

search

Character vector to search for

token

Sakbe API token supplied by INEGI

Value

Data.frame

Author(s)

Eduardo Flores

Examples

# All id's in Monterrey, Mex.
## Not run: 
token <- "webservice_token"
dest_ids <- inegi_destiny("monterrey", token)

## End(Not run)

Exports of Mexico to trade partners

Description

Returns exports to main trading partners of all products. Regions are the following: United States, Canada, China, CentralAmerica, SouthAmerica

Usage

inegi_partner_exports(token)

Arguments

token

API token supplied by INEGI

Value

data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token <- "webservice_token"
xbycountry <- inegi_partner_exports(token)

## End(Not run)

Returns the route between two points in Mexico

Description

Uses SAKBE API to return a route between two destiny id's considering the given parameters.

Usage

inegi_route(from, to, token, pref, vehicle, calc_cost = FALSE,
  rawJSON = FALSE)

Arguments

from

Destiny id from where the route begins

to

Destiny id of end of route

token

Sakbe API token supplied by INEGI

pref

Preference for road: 1 = with tolls (cuota), 2 = without tolls (libre), 2 = suggested route

vehicle

Vehicle choice: 0 = motorcycle, 1 = auto, 2 = two axis bus, 3 = three axis bus, 4 = four axis bus, 5 = two axis truck, 6 = three axis truck, 7 = four axis truck, 8 = five axis truck, 9 = six axis truck, 10 = seven axis truck, 11 = eight axis truck, 12 = nine axis truck.

calc_cost

if TRUE will use the price of gasoline to calculate total cost of trip. Very experimental, defaults to FALSE.

rawJSON

if TRUE returns only the JSON data, not parsed

Value

list

Note

To calculate the cost, it is wiser to use the more conservative estimate. Thus, this function assumes a premium type of gasoline (the most expensive) at the lower end bound of fuel-efficiency (11 kms per liter)

Author(s)

Eduardo Flores

References

See the official API here: http://www.inegi.org.mx/desarrolladores/sakbe/apisakbe.aspx

Examples

# Macroplaza in Monterrey to Mexico City airport.
## Not run: 
token <- "webservice_token"
route <- inegi_route(from = 6940, to = 57, token, pref = 2, vehicle = 1)

## End(Not run)

Sectorial activity indices

Description

Returns indexes of economic sector as defined in INEGI (subsectors of IGAE). None of the series are seasonally adjusted.

Usage

inegi_sectors(token)

Arguments

token

API token supplied by INEGI

Value

data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token <- "webservice_token"
sectors <- inegi_sectors(token)

## End(Not run)

Returns INEGI data series

Description

Returns a data.frame with the time series chosen from INEGI webservice. If the parameter Metadata is TRUE, a list is returned with two objects: data and metadata.

Usage

inegi_series(series_id, token, geography = "00", database = "BIE",
  metadata = FALSE, lastonly = FALSE, as_tt = FALSE,
  as_compact = FALSE)

Arguments

series_id

an indicator ID. These are obtained via the INEGI API documentation.

token

API token supplied by INEGI.

geography

Geography code of INEGI. Defaults to 00 (National)

database

Is the id from BIE (Banco de Informacion Economica) or BISE (Banco de Indicadores)? Defaults to BIE. To learn more about what database your indicator is stored in, visit INEGI docs.

metadata

Defaults to FALSE, if TRUE, returns a list with metadata information.

lastonly

Do you want only the last observation? Defaults to FALSE.

as_tt

Do you want the output of the data.frame to be a tibble time object? Defaults to FALSE.

as_compact

Do you want the output always as a data.frame or time tibble? If the output contains metadata, each data point will be replicated in a column. If the output does not contain metadata there is no change. Previously, this was achieved with compact_inegi_series.

Value

data.frame or list

Note

Adding the entire INEGI URL as a series is deprecated since v3, due to a change of API specifications in INEGI. INEGI docs can be found at: https://www.inegi.org.mx/servicios/api_indicadores.html. Coercing biweekly indicators to monthly is also deprecated inside this function. Use tibbletime functions to coerce instead.

Author(s)

Eduardo Flores

Examples

## Not run: 
# General INPC series
token <- "webservice_token"
inpc_id <- "216064"
INPC <- inegi_series(inpc_id, token)

## End(Not run)

Returns multiple INEGI data series

Description

Returns a data.frame with multiple time series chosen from INEGI webservice. The output will always be a data.frame (not tibble) with compacted metadata. (See inegi_series to understand as_tt = FALSE and as_compact = TRUE).

Usage

inegi_series_multiple(series_id, token, names = NULL, geography = "00",
  database = "BIE")

Arguments

series_id

A vector of indicator ID's. These are obtained via the INEGI API documentation.

token

API token supplied by INEGI.

names

Optional vector of names to assign to each id. If NULL, a numerical index is assigned.

geography

Geography code of INEGI. Defaults to 00 (National)

database

Is the id from BIE (Banco de Informacion Economica) or BISE (Banco de Indicadores). Defaults to BIE. To learn more about what database your indicator is stored in, visit INEGI docs.

Value

data.frame

Note

Adding the entire INEGI URL as a series is deprecated since v3, due to a change of API specifications in INEGI. INEGI docs can be found at: https://www.inegi.org.mx/servicios/api_indicadores.html. Coercing biweekly indicators to monthly is also deprecated inside this function. Use tibbletime functions to coerce instead.

Author(s)

Eduardo Flores

Examples

## Not run: 
# General INPC series
token <- "webservice_token"
some_series <- c("216064", "216097")
result <- inegi_series_multiple(some_series, token)

## End(Not run)

Student Price Index

Description

Returns the student price index. See http://enelmargen.org/ds/ipe/ for more information.

Usage

inegi_stind(token)

Arguments

token

API token supplied by INEGI

Value

Data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token <- "webservice_token"
studentinflation <- inegi_stind(token)

## End(Not run)

Terms of trade for Mexico

Description

Returns the terms of trade for Mexico, defined as the price index of exports over the price index of imports.

Usage

inegi_tot(token)

Arguments

token

API token supplied by INEGI

Value

data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token <- "webservice_token"
tot <- inegi_tot(token)

## End(Not run)

Trade balance

Description

Returns exports, imports and trade balance (all products, services and countries) in a data.frame. Wrapper for inegi_series() and YoY().

Usage

inegi_tradebal(token)

Arguments

token

API token supplied by INEGI

Value

data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token<-"webservice_token"
external_com <- inegi_tradebal(token)

## End(Not run)

INEGI Direct Indicators

Description

Returns common indicators, for simplicity. Will return as a list, with metadata and tibble time dataframe.

Usage

inind_commerce(token)

inind_auto(token)

inind_gdp(token)

inind_fx(token)

inind_unemp(token)

inind_prices(token)

Arguments

token

API token supplied by INEGI

Details

inind_commerce = terciary industrial activity (commercial activity monthly). inind_auto = auto production. innind_gpd = Gross Domestic Product. inind_fx = USDMXN Exchange rate. inind_unemp = Unemployment rate. inind_prices = National price index (for inflation).

Value

Data.frame

Author(s)

Eduardo Flores

Examples

## Not run: 
token<-"webservice_token"
commerce_rate <- inind_commerce(token)

## End(Not run)

Makes a grid set of coordinates

Description

Returns a set of coordinates that intertwine to create an area larger than 5 kilometers. Suggestion by Arturo Cardenas https://github.com/arturocm.

Usage

make_grid(lat1, lat2, lon1, lon2, space_lat = 0.07, space_lon = 0.07)

Arguments

lat1

First corner (latitud). Must be numeric.

lat2

Second corner (latitud). Must be numeric.

lon1

First corner (longitud). Must be numeric.

lon2

Second corner (longitud). Must be numeric.

space_lat

Space between latitud coordinates defaults to 0.07 degrees

space_lon

Space between longitud coordinates defaults to 0.07 degrees

Value

Data.frame

Author(s)

Arturo Cardenas

See Also

denue_grid

Examples

latitud1 <- 25.66919
latitud2 <- 25.169194
longitud1 <- -100.30990
longitud2 <- -101.20102
setofcoords <- make_grid(latitud1, latitud2, longitud1, longitud2)