knitr::opts_chunk$set(echo = TRUE) library(devtools) library(testthat) library(magrittr) library(owmr)
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
master
develop
# stable install.packages("owmr") # unstable devtools::install_github("crazycapivara/owmr") # bleeding edge devtools::install_github("crazycapivara/owmr", ref = "develop")
See OpenWeatherMap's API documentation for optional parameters, which can be passed to all functions fetching weather data via the ...
parameter in R
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
# get current weather data by city name (res <- get_current("London", units = "metric") %>% owmr_as_tibble()) %>% names() res[, 1:6] # ... by city id (rio <- search_city_list("Rio de Janeiro")) %>% as.list() get_current(rio$id, units = "metric") %>% owmr_as_tibble() %>% .[, 1:6] # 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] # get forecast forecast <- get_forecast("London", units = "metric") %>% owmr_as_tibble() forecast[, 1:6] # 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)
or type
?owmr
devtools::test()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.