Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hrbrmstr/darksky

:cloud: R interface to the Dark Sky API [APPLE IS SHUTTING DOWN THE API 2022-12-31]
https://github.com/hrbrmstr/darksky

darksky darksky-api darksky-api-powered darksky-weather-api darkskyapi r rstats weatherkit

Last synced: about 2 months ago
JSON representation

:cloud: R interface to the Dark Sky API [APPLE IS SHUTTING DOWN THE API 2022-12-31]

Awesome Lists containing this project

README

        

---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r include=FALSE}
knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.retina=2)
```

`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/")
```