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:

Installation

devtools::install_github("hrbrmstr/darksky")

OR

devtools::install.packages("darksky")
options(width=120)

Usage

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)

Test Results

library(darksky)
library(testthat)

date()

test_dir("tests/")


hrbrmstr/darksky documentation built on May 24, 2021, 4:08 p.m.