WeatherBitWrapper is an R package designed to retrieve weather data from the WeatherBit API. It provides easy access to current weather, severe weather alerts, and 16-day forecasts, returning structured data frames for easy analysis in R.
The following workflow diagram illustrates the overall structure of the package, detailing how user inputs are processed through various function categories to interact with the WeatherBit API and return structured outputs.
# Install from GitHub
library(remotes)
devtools::install_github("TenTen-Teng/WeatherBitRWrapper")
# Import library
library('WeatherBitRWrapper')
[!TIP] Sign up Weatherbit API Key
Go to Weatherbit API website. Sign up and get an API key. Then save the API key to R environment. Please refer here.
This package includes the following core functions:
get_current_temperature(location, by = "city")
– Retrieves the current temperature, feels-like temperature, and dew point.get_current_wind(location, by = "city")
– Provides wind speed, direction, and gusts.get_current_precipitation(location, by = "city")
– Fetches precipitation rate, humidity, and cloud coverage.
weather_alert_lat(lat, lon)
– Get alerts using latitude and longitude.weather_alert_city(city, state = NULL, country = NULL)
– Get alerts by city name.weather_alert_postal(postal_code, country = NULL)
– Get alerts by postal code.weather_alert_id(city_id)
– Get alerts using a city ID.
get_forecast_by_city(city, day = 16)
– Retrieves a forecast for a given city.get_forecast_by_lat_lon(lat, lon, day = 16)
– Retrieves a forecast using latitude/longitude.get_forecast_by_postal_code(postal_code, country, day = 16)
– Retrieves a forecast using postal code.get_forecast_by_city_id(city_id, day = 16)
– Retrieves a forecast using a city ID.
Below are quick examples for fetching current weather data, severe weather alerts, and 16-day forecasts. For a full guide on using this package, please refer to the vignette.
# Import library
library(WeatherBitWrapper)
# Get current temperature for New York
get_current_temperature(location = "New York", by = "city")
# Get severe weather alerts for Los Angeles
weather_alert_city(city = "Los Angeles", state = "CA", country = "US")
# Get a 7-day weather forecast for postal code 10001
get_forecast_by_postal_code(postal_code = "10001", country = "US", day = 16)
Please see our vignette
- Set API key in the environment by opening the
.Renviron
file in RStudio usingfile.edit("~/.Renviron")
- Add
WEATHERBIT_API_KEY=your_actual_api_key_here
and saving the file.
TenTen-Teng |
Yuzhu Han |
Ieleniayu |