Created
July 28, 2020 20:44
-
-
Save chrismcg/a69d4035bd21d238000802017f22ef62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "Ireland Electricity" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
library(ghql) | |
library(jsonlite) | |
library(fpp3) | |
``` | |
```{r} | |
con <- GraphqlClient$new( | |
url = "https://sg.chrismcg.com/api" | |
) | |
#con$load_schema() | |
query <- Query$new() | |
query$query('data', ' | |
{ | |
co2_emissions: timeseries(from:"2015-01-01T00:00:00Z", variable:CO2_EMISSIONS) { | |
data | |
region | |
variable { | |
name | |
unit | |
} | |
} | |
} | |
') | |
result <- query$queries$data %>% | |
con$exec() %>% | |
jsonlite::fromJSON() | |
co2_emissions <- result$data$co2_emissions$data %>% | |
as_tibble() %>% | |
rename(timestamp = V1, value = V2) %>% | |
mutate(timestamp = as_datetime(timestamp), variable = "CO2_EMISSIONS") %>% | |
as_tsibble(variable, timestamp) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment