MyNixOS website logo
Description

OpenWeatherMap API Wrapper.

Accesses OpenWeatherMap's (owm) <https://openweathermap.org/> API. 'owm' itself is a service providing weather data in the past, in the future and now. Furthermore, 'owm' serves weather map layers usable in frameworks like 'leaflet'. In order to access the API, you need to sign up for an API key. There are free and paid plans. Beside functions for fetching weather data from 'owm', 'owmr' supplies tools to tidy up fetched data (for fast and simple access) and to show it on leaflet maps.

An R Interface to OpenWeatherMap

CRAN_Status_Badge

owmr accesses OpenWeatherMap's API, a service providing weather data in the past, in the future and now and furthermore, serving weather map layers usable in frameworks like leaflet. In order to access its API you have to sign up for an API key at

Builds

master

Travis-CI Build Status

develop

Travis-CI Build Status

Installation

# stable
install.packages("owmr")

# unstable
devtools::install_github("crazycapivara/owmr")

# bleeding edge
devtools::install_github("crazycapivara/owmr", ref = "develop")

Introduction

See OpenWeatherMap's API documentation for optional parameters, which can be passed to all functions fetching weather data via the ... parameter in R

Setup

library(owmr)

# first of all you have to set up your api key
owmr_settings("your_api_key")

# or store it in an environment variable called OWM_API_KEY (recommended)
Sys.setenv(OWM_API_KEY = "your_api_key") # if not set globally

Usage

# get current weather data by city name
(res <- get_current("London", units = "metric") %>%
  owmr_as_tibble()) %>% names()
##  [1] "dt_txt"              "temp"                "pressure"           
##  [4] "humidity"            "temp_min"            "temp_max"           
##  [7] "weather_id"          "weather_main"        "weather_description"
## [10] "weather_icon"        "wind_speed"          "wind_deg"           
## [13] "clouds_all"          "dt_sunrise_txt"      "dt_sunset_txt"
res[, 1:6]
## # A tibble: 1 x 6
##   dt_txt               temp pressure humidity temp_min temp_max
##   <chr>               <dbl>    <dbl>    <dbl>    <dbl>    <dbl>
## 1 2018-10-28 20:50:00  4.22     1017       81        3        6
# ... by city id
(rio <- search_city_list("Rio de Janeiro")) %>%
  as.list()
## $id
## [1] 3451190
## 
## $nm
## [1] "Rio de Janeiro"
## 
## $lat
## [1] -22.90278
## 
## $lon
## [1] -43.2075
## 
## $countryCode
## [1] "BR"
get_current(rio$id, units = "metric") %>%
  owmr_as_tibble() %>% .[, 1:6]
## # A tibble: 1 x 6
##   dt_txt               temp pressure humidity temp_min temp_max
##   <chr>               <dbl>    <dbl>    <dbl>    <dbl>    <dbl>
## 1 2018-10-28 21:00:00  23.2     1014       64       23       24
# get current weather data for cities around geo point
res <- find_cities_by_geo_point(
  lat = rio$lat,
  lon = rio$lon,
  cnt = 5,
  units = "metric"
) %>% owmr_as_tibble()

idx <- c(names(res[1:6]), "name")
res[, idx]
## # A tibble: 5 x 7
##   dt_txt            temp pressure humidity temp_min temp_max name         
##   <chr>            <dbl>    <dbl>    <dbl>    <dbl>    <dbl> <chr>        
## 1 2018-10-28 21:0…  23.2     1014       64       23       24 Rio de Janei…
## 2 2018-10-28 21:0…  23.2     1014       64       23       24 São Cristóvão
## 3 2018-10-28 21:0…  23.2     1014       69       23       24 Botafogo     
## 4 2018-10-28 21:0…  23.2     1014       69       23       24 Pavão-Pavaoz…
## 5 2018-10-28 21:0…  23.2     1014       64       23       24 Vila Joaniza
# get forecast
forecast <- get_forecast("London", units = "metric") %>%
  owmr_as_tibble()

forecast[, 1:6]
## # A tibble: 40 x 6
##    dt_txt               temp pressure humidity temp_min temp_max
##    <chr>               <dbl>    <dbl>    <dbl>    <dbl>    <dbl>
##  1 2018-10-28 21:00:00  2.76    1023.       71     2.76     4.22
##  2 2018-10-29 00:00:00  1.64    1021.       90     1.64     2.73
##  3 2018-10-29 03:00:00  2.54    1019.       99     2.54     3.27
##  4 2018-10-29 06:00:00  1.64    1018.       94     1.64     2   
##  5 2018-10-29 09:00:00  4.65    1016.       84     4.65     4.65
##  6 2018-10-29 12:00:00  8.44    1013.       77     8.44     8.44
##  7 2018-10-29 15:00:00  8.47    1010.       70     8.47     8.47
##  8 2018-10-29 18:00:00  5.96    1008.       76     5.96     5.96
##  9 2018-10-29 21:00:00  3.57    1005.       87     3.57     3.57
## 10 2018-10-30 00:00:00  3.07    1003.       97     3.07     3.07
## # ... with 30 more rows
# apply funcs to some columns
funcs <- list(
  temp = round,
  wind_speed = round
)
forecast %<>% parse_columns(funcs)

# do some templating ...
("{{dt_txt}}h {{temp}}°C, {{wind_speed}} m/s" %$$%
  forecast) %>% head(10)
##  [1] "2018-10-28 21:00:00h 3°C, 5 m/s" "2018-10-29 00:00:00h 2°C, 4 m/s"
##  [3] "2018-10-29 03:00:00h 3°C, 4 m/s" "2018-10-29 06:00:00h 2°C, 4 m/s"
##  [5] "2018-10-29 09:00:00h 5°C, 3 m/s" "2018-10-29 12:00:00h 8°C, 4 m/s"
##  [7] "2018-10-29 15:00:00h 8°C, 5 m/s" "2018-10-29 18:00:00h 6°C, 4 m/s"
##  [9] "2018-10-29 21:00:00h 4°C, 4 m/s" "2018-10-30 00:00:00h 3°C, 4 m/s"

Documentation

or type

?owmr

Run tests

devtools::test()
## Loading owmr

## owmr 0.7.4
##    another crazy way to talk to OpenWeatherMap's API
##    Documentation: type ?owmr or https://crazycapivara.github.io/owmr/
##    Issues, notes and bleeding edge: https://github.com/crazycapivara/owmr/

## Testing owmr

## city list: ..
## mock httr::GET current: ....
## current weather data for multiple cities: ......
## current weather data: ........
## _DEPRECATED: W.
## mock httr::GET forecast: ......
## parse columns: ..
## render operator: ...
## tidy up data: ...
## 
## Warnings ------------------------------------------------------------------
## 1. tidy up all (@test_deprecated.R#8) - 'tidy_up_' is deprecated.
## Use 'owmr_as_tibble' instead.
## See help("Deprecated")
## 
## DONE ======================================================================
Metadata

Version

0.8.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows