knitr::opts_chunk$set(echo = TRUE)

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
colnames(arg_id)
arg_id$id
arg_id$region$continent$id
arg_id <- arg_id$id

tl_id <- find_location("toulouse")$node
nrow(tl_id)
tl_id$typename

# we are looking for the city
tl_id <- tl_id[tl_id$typename == "City", ]
tl_id$country$name
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)
head(data.frame(
  from = flights$itineraries$source$station$name, to = flights$itineraries$destination$station$name,
  price = flights$itineraries$price$amount
))


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