R package to simply get daily weather data
simpleweather is an R package that provides a simple interface to get historical and forecasted weather. It does one thing: retrieve basic weather data for a given latitude, longitude location. No anguish to figure out which data source to use, weather variable to pick, or weather station to choose.
simpleweather is focused and therefore limited to only providing temperature (daily max in Fahrenheit), precipitation (True/False), and wind speed (mph). The package leverages NOAA for historical data and OpenWeather for the latest data. NOAA data is limited to the United States only.
library(simpleweather)
dates <- Sys.Date() + -7:2
lat <- 40.7812
long <- -73.9665
get_weather(dates, lat, long)
#> Using NOAA station LAGUARDIA AIRPORT, NY US
#> OpenWeather uses exact latitude, longitude provided
#> # A tibble: 10 × 6
#> date temperature precipitation wind is_forecast source
#> <date> <dbl> <lgl> <dbl> <lgl> <chr>
#> 1 2021-09-19 78 FALSE 18.1 FALSE NOAA
#> 2 2021-09-20 76 FALSE 15 FALSE NOAA
#> 3 2021-09-21 66.8 FALSE 6.62 FALSE OpenWeather
#> 4 2021-09-22 72.2 FALSE 4 FALSE OpenWeather
#> 5 2021-09-23 75.5 FALSE 5.01 FALSE OpenWeather
#> 6 2021-09-24 69.8 FALSE 5.75 FALSE OpenWeather
#> 7 2021-09-25 67.8 FALSE 6.91 FALSE OpenWeather
#> 8 2021-09-26 72.0 FALSE 15.5 TRUE OpenWeather
#> 9 2021-09-27 78.2 FALSE 15.8 TRUE OpenWeather
#> 10 2021-09-28 73.5 TRUE 10.1 TRUE OpenWeather
The package is available through GitHub and can be installed via devtools.
# install.packages("devtools")
devtools::install_github("joemarlo/simpleweather")
Requires API keys for the NOAA API and OpenWeather API. You can request those keys for free here and here.
And then log your API keys via the set_api_key_* functions.
set_api_key_noaa("<key>")
set_api_key_openweather("<key>")
Please credit NOAA and/or OpenWeather as your weather data provider depending on your use.
2021 September
Find the code here: github.com/joemarlo/simpleweather