README.md

R Flights

CRAN
status CRAN
logs Lifecycle:
stable Travis build
status Coverage
status

Query plane tickets, from several airlines, using the Kiwi API (similar to Google Flights).

The API is documented at https://docs.kiwi.com/.

Installation

You can install the rflights package from CRAN:

install.packages("rflights")

Or get the latest version from GitHub:

if (!require("remotes")) {
  install.packages("remotes")
}
remotes::install_github("jcrodriguez1989/rflights")

Usage

Get city or country IDs

library("rflights")
# get Argentina and toulouse IDs
arg_id <- find_location("Argentina", "COUNTRY")$node
nrow(arg_id) # only one result, so it might be the one
## [1] 1
colnames(arg_id)
##  [1] "typename" "isPlace"  "id"       "legacyId" "name"     "slug"    
##  [7] "slugEn"   "gps"      "rank"     "code"     "region"
arg_id$id
## [1] "Country:AR"
arg_id$region$continent$id
## [1] "Continent:south-america"
arg_id <- arg_id$id

tl_id <- find_location("toulouse")$node
nrow(tl_id)
## [1] 3
tl_id$typename
## [1] "City"          "Station"       "TouristRegion"
# we are looking for the city
tl_id <- tl_id[tl_id$typename == "City", ]
tl_id$country$name
## [1] "France"
tl_id <- tl_id$id

Get flight prices

# get flights from Argentina to toulouse for this month
flights <- get_flights(
  fly_from = "Country:AR", fly_to = "City:toulouse_fr",
  departure_from = Sys.Date(), departure_to = Sys.Date() + 30
)
nrow(flights$itineraries)
head(flights$itineraries$price$amount)

Fly to anywhere

Find plane tickets from my city to anywhere, from today to 2 next weeks.

# I am a nomad, let's go anywhere!
flights <- search_flights(
  fly_from = "Country:AR",
  departure_from = Sys.Date(), departure_to = Sys.Date() + 2 * 7
)
nrow(flights$itineraries)
## [1] 53
head(data.frame(
  from = flights$itineraries$source$station$name, to = flights$itineraries$destination$station$name,
  price = flights$itineraries$price$amount
))
##                                                          from
## 1                            Ministro Pistarini International
## 2                            Ministro Pistarini International
## 3                            Ministro Pistarini International
## 4 Ingeniero Aeronáutico Ambrosio L.V. Taravella International
## 5                            Ministro Pistarini International
## 6                            Ministro Pistarini International
##                              to price
## 1 John F. Kennedy International   414
## 2                       Gatwick   559
## 3             Barcelona–El Prat   554
## 4  Adolfo Suárez Madrid–Barajas   462
## 5          Narita International   832
## 6     Charles de Gaulle Airport   560


jcrodriguez1989/rflights documentation built on Nov. 21, 2024, 2:23 a.m.