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")
#> $Sunrise
#> [1] "07:01:25 AM"
#>
#> $Sunset
#> [1] "04:11:20 PM"
#>
#> $Date
#> [1] "2019-12-09"
#>
#> $Location
#> [1] "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:
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:
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 City State
#> 337 BID Block Island RI
#> 1695 NCO North Kingstown RI
#> 1745 NPT Newport RI
#> 2041 PVD Providence RI
#> 2263 SFZ Smithfield RI
#> 2747 WST Westerly RI
#> 2826 ZXU North Kingstown RI
#> Airport
#> 337 Block Island State
#> 1695 Quonset State Air Reserve National Guard Helipad
#> 1745 Newport State
#> 2041 Theodore Francis Green State
#> 2263 North Central State
#> 2747 Westerly State
#> 2826 Quonset State
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: