-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectricity.R
53 lines (48 loc) · 1.54 KB
/
electricity.R
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
#### Data modules for the electricity queries group
#' Electricity Data Module
#'
#' Produce electricity by region.
#'
#' The raw table used by this module has columns:
#' \itemize{
#' \item{scenario}
#' \item{region}
#' \item{sector}
#' \item{subsector}
#' \item{technology}
#' \item{year}
#' \item{value}
#' \item{Units}
#' }
#'
#' @keywords internal
module.electricity <- function(mode, allqueries, aggkeys, aggfn, years,
filters, filter_operator, ounit)
{
if(mode == GETQ) {
# Return titles of necessary queries
# For more complex variables, will return multiple query titles.
'Electricity'
}
else {
## silence notes on package checks
subsector <- technology <- NULL
message('Function for processing variable: Electricity')
# Add CCS to subsector
elct <- allqueries$Electricity %>%
dplyr::mutate(subsector = sub('rooftop_pv', 'solar', subsector),
subsector = paste0(subsector,
dplyr::if_else(grepl('CCS', technology), ' CCS', '')))
elct <- filter(elct, years, filters, filter_operator)
elct <- aggregate(elct, aggfn, aggkeys)
if(!is.na(ounit)) {
## skip unit conversion if output unit not specified.
cfac <- unitconv_energy(elct$Units[1], ounit)
if(!is.na(cfac)) {
elct$value <- elct$value * cfac
elct$Units <- ounit
}
}
elct
}
}