-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathREADME.Rmd
105 lines (77 loc) · 2.99 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r include=FALSE}
knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.retina=2)
```
<!-- [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/0.1.0/active.svg)](http://www.repostatus.org/#active) -->
<!-- [![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/darksky/master.svg)](https://codecov.io/github/hrbrmstr/darksky?branch=master) -->
<!-- [![Build Status](https://travis-ci.org/hrbrmstr/darksky.svg?branch=master)](https://travis-ci.org/hrbrmstr/darksky) -->
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/gq0uxmae9ii64g6q?svg=true)](https://ci.appveyor.com/project/hrbrmstr/darksky) -->
<!-- [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/darksky)](https://cran.r-project.org/package=darksky) -->
<!-- ![downloads](http://cranlogs.r-pkg.org/badges/grand-total/darksky) -->
`darksky` : Tools to Work with the Dark Sky API
- Dark Sky API Docs: https://darksky.net/dev/docs
- Dark Sky Dev site: https://darksky.net/dev/
The following functions are implemented:
- `darksky_api_key` : Get or set `DARKSKY_API_KEY` value
- `get_current_forecast` : Retrieve the current forecast (for the next week)
- `get_forecast_for` : Retrieve weather data for a specific place/time
- `plot.darksky` : Plot method for `darksky` objects
- `print.darksky` : A tad more human readable default printing
### Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/darksky")
```
OR
```{r eval=FALSE}
devtools::install.packages("darksky")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
### Usage
```{r}
library(darksky)
library(tidyverse)
# current verison
packageVersion("darksky")
now <- get_current_forecast(43.2672, -70.8617)
print(now)
```
Historical (using `Date` objects):
```{r}
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()
```
```{r}
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
```{r}
library(darksky)
library(testthat)
date()
test_dir("tests/")
```