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.
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")
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.
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")
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")
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")
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.