Skip to content

Commit

Permalink
Include pre-built vignettes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-g committed Nov 28, 2019
1 parent 7f17afa commit 55f3327
Show file tree
Hide file tree
Showing 7 changed files with 1,052 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
^doc$
^CRAN-RELEASE$
^Meta$
^CRAN-RELEASE$
^.*\.Rproj$
^\.Rproj\.user$
^README\.R?md$
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Meta
doc
.Rproj.user/
.Rhistory
.RData
Expand Down
Binary file added Meta/vignette.rds
Binary file not shown.
30 changes: 16 additions & 14 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,32 @@

0 errors | 0 warnings | 0 notes

* r-hub debian builds:
* r-hub debian R-devel build:

0 errors | 0 warnings | 2 notes

* r-hub ubuntu and winbuilder builds:
* All other r-hub builds:

0 errors | 0 warnings | 1 note

### NOTES:

* **r-hub ubuntu and debian**: False-positive warning about
(possibly) invalid URL <https://www.eia.gov/outlooks/archive/ieo17/>.
This only occurs on r-hub builder and not other builds. I have checked this
URL manually and it is correct and working when I visit it from a web
* **r-hub builds**: False-positive warning about
two (possibly) invalid URLs <https://www.eia.gov/outlooks/archive/ieo17/> and
<https://www.eia.gov/electricity/monthly/epm_table_grapher.php?t=epmt_6_07_a>.
This only occurs on r-hub builder and not other builds. I have checked both
URLs manually and they correct and working when I visit them from a web
browser.

This URL is the underlying source of the data provided by this package
(it's listed in "\source" lines in td_trends.Rd and td_values.Rd).
It is a third-party web site operated by the U.S. Department of Energy
and is not under my control.

* **r-hub debian only**: False-positive warning about (possible) misspellings
for four people's names in DESCRIPTION: "Kaya", "Keiichi", "Yoichi", and
"Yokobori". These names are spelled correctly.
These URLs reference the underlying source of the data provided by this
package (they are listed in "\source" lines in `td_trends.Rd` and
`td_values.Rd`, and a "\references" line in `generation_capacity.Rd`).
They reference a third-party web site operated by the U.S. Department of
Energy and is not under my control.

* **r-hub debian R-devel only**: False-positive warning about (possible)
misspellings for four people's names in DESCRIPTION: "Kaya", "Keiichi",
"Yoichi", and "Yokobori". These names are spelled correctly.

## Reverse dependencies

Expand Down
116 changes: 116 additions & 0 deletions doc/policy_analysis.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
echo = TRUE,
collapse = TRUE,
comment = "#>"
)

## ----load_data----------------------------------------------------------------
suppressPackageStartupMessages({
library(magrittr)
library(dplyr)
library(stringr)
library(tidyr)
library(purrr)
library(broom)
library(knitr)
library(scales)
library(kayadata)
})

kaya <- get_kaya_data("United States")

## ----plot_P_1990, fig.cap = str_c("Trend in population for U.S. from 1990--", max(kaya$year, na.rm = T))----
plot_kaya(kaya, "P", log_scale = TRUE, start_year = 1990, trend_line = TRUE, points = FALSE) +
theme_bw()

## ----plot_g_1990, fig.cap = str_c("Trend in per-capita GDP for U.S. from 1990--", max(kaya$year, na.rm = T))----
plot_kaya(kaya, "g", log_scale = TRUE, start_year = 1990, trend_line = TRUE, points = FALSE) +
theme_bw()

## ----plot_e_1990, fig.cap = str_c("Trend in primary-energy intensity of the U.S. economy from 1990--", max(kaya$year, na.rm = T))----
plot_kaya(kaya, "e", log_scale = TRUE, start_year = 1990, trend_line = TRUE, points = FALSE) +
theme_bw()

## ----plot_f_1990, fig.cap = str_c("Trend in the carbon-dioxide intensity of the U.S. energy supply from 1990--", max(kaya$year, na.rm = T))----
plot_kaya(kaya, "f", log_scale = TRUE, start_year = 1990, trend_line = TRUE, points = FALSE) +
theme_bw()

## ----plot_f_2005, fig.cap = str_c("Trend in the carbon-dioxide intensity of the U.S. energy supply from 2005--", max(kaya$year, na.rm = T))----
plot_kaya(kaya, "f", log_scale = TRUE, start_year = 2005, trend_line = TRUE, points = FALSE) +
theme_bw()

## ----compute-bottom-up-rates--------------------------------------------------
vars <- c("P", "g", "e", "f")
historical_trends <- map_dbl(vars,
~kaya %>%
gather(key = variable, value = value, -region, -year) %>%
filter(variable == .x,
year >= ifelse(.x == "f", 2005, 1990)) %>%
lm(log(value) ~ year, data = .) %>% tidy() %>%
filter(term == "year") %$% estimate
) %>% set_names(vars)

tibble(Variable = names(historical_trends),
Rate = map_chr(historical_trends, ~percent(.x, 0.01))) %>%
kable(align = c("c", "r"))

## ----implied_rate_F-----------------------------------------------------------
ref_year <- 2005
target_years <- c(2025, 2050)
target_reduction <- c(0.26, 0.80)

F_ref <- kaya %>% filter(year == ref_year) %$% F
F_target <- tibble(year = target_years, F = F_ref * (1 - target_reduction)) %>%
mutate(implied_rate = log(F / F_ref) / (year - ref_year))

F_target %>%
mutate(implied_rate = map_chr(implied_rate, ~percent(.x, 0.01))) %>%
rename("Target F" = F, "Implied Rate" = implied_rate) %>%
kable(align = c("crr"), digits = 0)

## ----implied_decarb_bottom_up-------------------------------------------------
implied_decarb_rates <- F_target %>%
transmute(year, impl_F = implied_rate,
hist_G = historical_trends['P'] + historical_trends['g'],
hist_ef = historical_trends['e'] + historical_trends['f'],
impl_ef = impl_F - hist_G)

implied_decarb_rates %>%
mutate_at(vars(starts_with("hist_"), starts_with("impl_")),
list(~map_chr(., ~percent(.x, 0.01)))) %>%
select(Year = year,
"implied F" = impl_F,
"historical G" = hist_G,
"implied ef" = impl_ef,
"historical ef" = hist_ef
) %>%
kable(align="rrrrr")

## ----top_down_trends----------------------------------------------------------
top_down_trends <- get_top_down_trends("United States")

top_down_trends %>% select(P, G, E) %>%
mutate_all(list(~map_chr(., ~percent(.x, 0.01)))) %>%
rename("P trend" = P, "G trend" = G, "E trend" = E) %>%
kable(align="rrr")

## ----implied_decarb_top_down--------------------------------------------------
implied_decarb_rates_top_down <- F_target %>%
transmute(year, impl_F = implied_rate,
top_down_E = top_down_trends$E,
hist_f = historical_trends['f'],
impl_f = impl_F - top_down_E)

implied_decarb_rates_top_down %>%
mutate_at(vars(starts_with("hist_"), starts_with("impl_"),
starts_with("top_down")),
list(~map_chr(., ~percent(.x, 0.01)))) %>%
select(Year = year,
"implied F" = impl_F,
"top-down E" = top_down_E,
"implied f" = impl_f,
"historical f" = hist_f
) %>%
kable(align="rrrrr")

Loading

0 comments on commit 55f3327

Please sign in to comment.