knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.retina=2)
darksky
: Tools to Work with the Dark Sky API
The following functions are implemented:
darksky_api_key
: Get or set DARKSKY_API_KEY
valueget_current_forecast
: Retrieve the current forecast (for the next week)get_forecast_for
: Retrieve weather data for a specific place/timeplot.darksky
: Plot method for darksky
objectsprint.darksky
: A tad more human readable default printingdevtools::install_github("hrbrmstr/darksky")
OR
devtools::install.packages("darksky")
options(width=120)
library(darksky) library(tidyverse) # current verison packageVersion("darksky") now <- get_current_forecast(43.2672, -70.8617) print(now)
Historical (using Date
objects):
seq(Sys.Date()-10, Sys.Date(), "1 day") %>% map(~get_forecast_for(43.2672, -70.8617, .x)) %>% map_df("hourly") %>% ggplot(aes(x=time, y=temperature)) + geom_line()
then <- get_forecast_for(43.2672, -70.8617, "2013-05-06T12:00:00-0400", add_headers=TRUE) print(then) # getting data for more than one location more_than_one <- data.frame(loc=c("Maine", "Seattle"), lat=c(43.2672, 47.6097), lon=c(70.8617, 122.3331), when=c("2013-05-06T12:00:00-0400", "2013-05-06T12:00:00-0400"), stringsAsFactors=FALSE) bigger_list <- pmap(list(more_than_one$lat, more_than_one$lon, more_than_one$when), get_forecast_for) names(bigger_list) <- more_than_one$loc bigger_list$Seattle bigger_list$Maine print(sprintf("You have used %s API calls.", then$`x-forecast-api-calls`)) plot(now)
library(darksky) library(testthat) date() test_dir("tests/")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.