Introduction"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(SunsetTSA)

The SunsetTSA package contains a sunrise_sunset() function to get sunrise and sunset times at any U.S. airport by airport code. Data come from a U.S. Transportation Security Administration API (no key needed).

The package also includes several functions to look up three-letter codes for U.S. airports.

Get sunrise and sunset times

Run sunrise_sunset("3-letter airport code") to get a list with Sunrise, Sunset, Date, and Location (which is the airport code you entered). If you don't specify a date, it defaults to today. For example:

sunrise_sunset("BOS")

To get results for another day, enter a date in "yyyy-mm-dd" format, such as this for Anchorage, Alaska's main airport on the 2020 summer solstice:

sunrise_sunset("ANC", "2020-06-20")

Get 3-letter airport codes

SunsetTSA also has several functions for looking up 3-letter airport codes. It will return a data frame with any matches including columns for Code, City, State, and Airport.

Data come from the U.S. Bureau of Transportation Statistics; I downloaded a CSV file from https://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRPORT.

By city name

The airport_codes_by_city() function has one required argument, city name, and an optional state name, such as:

airport_codes_by_city("Providence")
airport_codes_by_city("Greenville", "SC")

All codes in a state

The airport_codes_by_state() function will return all available codes in a state, with the two-letter postal abbreviation as the argument:

airport_codes_by_state("RI")

Code by airport name

You can also try looking up the code by airport name or partial airport name with airport_codes_by_name(). However, you'll need part of the same name that the Bureau of Transportation uses. So, while you may refer to one of New York City's airport as "JFK", you'd need to know that it's "John F. Kennedy International" to the BTS. "Kennedy" would also work:

airport_codes_by_name("Kennedy")


Try the SunsetTSA package in your browser

Any scripts or data that you put into this service are public.

SunsetTSA documentation built on Dec. 16, 2019, 5:43 p.m.