Skip to content

TenTen-Teng/WeatherBitRWrapper

Repository files navigation

WeatherBitWrapper

workflow

Introduction

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.

WeatherBitRWrapper Workflow

Installation

# 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.

Functions Overview

This package includes the following core functions:

1. Current Weather 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.

2. Severe Weather Alerts

  • 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.

3. 16-Day Forecast

  • 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.

Example Usage

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)

Fetching Current Weather

# Get current temperature for New York
get_current_temperature(location = "New York", by = "city")

Retrieving Severe Weather Alerts

# Get severe weather alerts for Los Angeles
weather_alert_city(city = "Los Angeles", state = "CA", country = "US")

Getting a 7-Day Forecast

# Get a 7-day weather forecast for postal code 10001
get_forecast_by_postal_code(postal_code = "10001", country = "US", day = 16)

Vignettes

Please see our vignette

Questions

How to set up API key to R environment?

  1. Set API key in the environment by opening the .Renviron file in RStudio using file.edit("~/.Renviron")
  2. Add WEATHERBIT_API_KEY=your_actual_api_key_here and saving the file.

Contributor

TenTen-Teng
TenTen-Teng
yz031326
Yuzhu Han
Ieleniayu
Ieleniayu

About

A R wrapper package for Weatherbit API.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •