Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lintr warnings and other format problems #560

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '38506518'
ValidationKey: '38526511'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrremind: MadRat REMIND Input Data Package'
version: 0.192.6
version: 0.192.7
date-released: '2024-09-27'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.192.6
Version: 0.192.7
Date: 2024-09-27
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export(convertUNFCCC)
export(convertUNIDO)
export(convertUSGS)
export(filter_historical_mif)
export(fullThresholds)
export(fullTHRESHOLDS)
export(readADVANCE_WP2)
export(readAGEB)
export(readAR6GWP)
Expand Down
11 changes: 6 additions & 5 deletions R/fullThresholds.R → R/fullTHRESHOLDS.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' validationConfig or "full" to export all pipeline data
#'
#' @export
fullThresholds <- function(type = "config") {
fullTHRESHOLDS <- function(type = "config") {

# get region mappings for aggregation ----
# Determines all regions data should be aggregated to by examining the columns
# of the `regionmapping` and `extramappings` currently configured.
Expand Down Expand Up @@ -53,8 +54,8 @@ fullThresholds <- function(type = "config") {
warnNA = FALSE, try = FALSE, years = years)

wind <- calcOutput("ProjectPipelines", subtype = "wind",
aggregate = columnsForAggregation, round = 3,
warnNA = FALSE, try = FALSE, years = years)
aggregate = columnsForAggregation, round = 3,
warnNA = FALSE, try = FALSE, years = years)

solar <- calcOutput("ProjectPipelines", subtype = "solar",
aggregate = columnsForAggregation, round = 3,
Expand Down Expand Up @@ -137,13 +138,13 @@ fullThresholds <- function(type = "config") {
out <- out[, , c("min_", "max_"), pmatch = TRUE] %>%
as.quitte() %>%
pivot_wider(names_from = "status") %>%
select(-scenario)
select(-"scenario")
# exclude rows without any threshold
out[!(is.na(out$min_red)
& is.na(out$min_yel)
& is.na(out$max_yel)
& is.na(out$max_red)), ] %>%
write.csv(file = outfile, row.names = FALSE, quote = FALSE)
utils::write.csv(file = outfile, row.names = FALSE, quote = FALSE)

} else {
warning("`type` must be either `full` or `config`")
Expand Down
27 changes: 13 additions & 14 deletions R/readGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ readGlobalEnergyMonitor <- function() {
# GEM GIPT 2024
# file available after filling out questionnaire:
# https://globalenergymonitor.org/projects/global-integrated-power-tracker/download-data/
d <- read_excel("Global-Integrated-Power-June-2024.xlsx",
d <- readxl::read_excel("Global-Integrated-Power-June-2024.xlsx",
sheet = "Power facilities",
trim_ws = TRUE,
col_types = "text") %>%
Expand All @@ -32,11 +32,13 @@ readGlobalEnergyMonitor <- function() {
filter(status %in% c("announced", "pre-construction", "construction", "operating")) %>%
# ASSUMPTION: rows with empty start year are ignored
# only look at pipeline until 2030
filter(!is.na(start), start < 2031) %>%
filter(!is.na(.data$start), .data$start < 2031) %>%
# Oil/Gas needs to be separated by technology or fuel (seems complicated?)
# remove for now
filter(variable != "oil/gas") %>%
mutate(start = as.numeric(start), end = as.numeric(end), value = as.numeric(value))
filter(.data$variable != "oil/gas") %>%
mutate(start = as.numeric(.data$start),
end = as.numeric(.data$end),
value = as.numeric(.data$value))

# no end year defined:
# use average lifetime of technology (from generisdata_tech)
Expand All @@ -51,10 +53,10 @@ readGlobalEnergyMonitor <- function() {
# find all of these cases and put them in 2 rows, one per country
d <- rbind(
d[is.na(d$c2), ],
d[!is.na(d$c2), ] %>% mutate(region = c1, value = as.numeric(v1)),
d[!is.na(d$c2), ] %>% mutate(region = c2, value = as.numeric(v2))
d[!is.na(d$c2), ] %>% mutate(region = .data$c1, value = as.numeric(.data$v1)),
d[!is.na(d$c2), ] %>% mutate(region = .data$c2, value = as.numeric(.data$v2))
) %>%
select(-c1, -c2, -v1, -v2)
select(-"c1", -"c2", -"v1", -"v2")

# use proper variable names
d[d$variable == "coal", "variable"] <- "Cap|Electricity|Coal"
Expand All @@ -77,7 +79,7 @@ readGlobalEnergyMonitor <- function() {

# transform data from list of capacities with start and end date
# to sum of active capacities in 2025 and 2030
d <- mutate(d, end = pmin(end, 2030)) # improves performance of next step
d <- mutate(d, end = pmin(.data$end, 2030)) # improves performance of next step
tmp_list <- vector("list", nrow(d))
for (i in seq_len(nrow(d))) {
tmp_list[[i]] <- data.frame(
Expand All @@ -86,9 +88,9 @@ readGlobalEnergyMonitor <- function() {
)
}
tmp <- do.call(rbind, tmp_list) %>%
group_by(region, variable, status, period) %>%
summarise(value = sum(value)) %>%
filter(period %in% c(2020, 2025, 2030))
group_by(.data$region, .data$variable, .data$status, .data$period) %>%
summarise(value = sum(.data$value)) %>%
filter(.data$period %in% c(2020, 2025, 2030))

# convert to magclass object
x <- as.magpie(tmp, spatial = "region")
Expand All @@ -103,9 +105,6 @@ readGlobalEnergyMonitor <- function() {
add_dimension(dim = 3.1, add = "variable", nm = "Cap|Electricity|Wind")
)

# collapse variable and status dimension into one
# getNames(x) <- gsub(pattern = "\\.", replacement = "|", x = getNames(x))

# convert MW to GW
x <- x / 1000
x <- add_dimension(x, dim = 3.4, add = "unit", nm = "GW")
Expand Down
12 changes: 6 additions & 6 deletions R/readIEA_CCUS.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ readIEA_CCUS <- function(subtype) {
# project types filter applied to source
projectTypes <- c("Full chain", "Storage", "T&S")

data <- read_excel("IEA CCUS Projects Database 2024.xlsx",
data <- readxl::read_excel("IEA CCUS Projects Database 2024.xlsx",
sheet = "CCUS Projects Database"
) %>%
select(
Expand Down Expand Up @@ -49,12 +49,12 @@ readIEA_CCUS <- function(subtype) {

# remove mixed-country data and attach single country data weighted by GDP
data <- data %>%
filter(!country %in% c("Japan-Malaysia", "Australia-Japan")) %>%
filter(!.data$country %in% c("Japan-Malaysia", "Australia-Japan")) %>%
rbind(
mutate(JM, country = "Japan", value = value*gdp_JPN/(gdp_JPN+gdp_MYS)),
mutate(JM, country = "Malaysia", value = value*gdp_MYS/(gdp_JPN+gdp_MYS)),
mutate(AJ, country = "Australia", value = value*gdp_AUS/(gdp_JPN+gdp_AUS)),
mutate(AJ, country = "Japan", value = value*gdp_JPN/(gdp_JPN+gdp_AUS))
mutate(JM, country = "Japan", value = .data$value*gdp_JPN/(gdp_JPN + gdp_MYS)),
mutate(JM, country = "Malaysia", value = .data$value*gdp_MYS/(gdp_JPN + gdp_MYS)),
mutate(AJ, country = "Australia", value = .data$value*gdp_AUS/(gdp_JPN + gdp_AUS)),
mutate(AJ, country = "Japan", value = .data$value*gdp_JPN/(gdp_JPN + gdp_AUS))
)

if (subtype == "historical") {
Expand Down
16 changes: 8 additions & 8 deletions R/readIEA_HSMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
#' @export
readIEA_HSMR <- function() {

x <- read_xlsx("IEA_Hydropower_Special_Market_Report.xlsx") %>%
x <- readxl::read_xlsx("IEA_Hydropower_Special_Market_Report.xlsx") %>%
# get capacities in 2030 by adding 2020 values to additions
# subtract pumped storage as it is not part of Cap Hydro in REMIND
mutate("2020_operational" = capacity_2020,
"2030_expected" = capacity_2020 + add_expected_2030 - of_that_pumped,
"2030_accelerated" = capacity_2020 + add_accelerated_2030 - of_that_pumped,
"2020_pumped" = cap_2020_pumped,
"2030_pumped" = cap_2020_pumped + of_that_pumped,
mutate("2020_operational" = .data$capacity_2020,
"2030_expected" = .data$capacity_2020 + .data$add_expected_2030 - .data$of_that_pumped,
"2030_accelerated" = .data$capacity_2020 + .data$add_accelerated_2030 - .data$of_that_pumped,
"2020_pumped" = .data$cap_2020_pumped,
"2030_pumped" = .data$cap_2020_pumped + .data$of_that_pumped,
variable = "Cap|Electricity|Hydro") %>%
pivot_longer(cols = c("2020_operational", "2030_expected",
"2030_accelerated", "2020_pumped", "2030_pumped"),
names_to = "year_scen") %>%
select(country, variable, year_scen, unit, value) %>%
separate(year_scen, c("year", "status")) %>%
select("country", "variable", "year_scen", "unit", "value") %>%
separate(.data$year_scen, c("year", "status")) %>%
as.magpie(spatial = "country")

x[, 2020, "accelerated"] <- x[, 2020, "operational"]
Expand Down
10 changes: 5 additions & 5 deletions R/readIEA_PRIS.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
readIEA_PRIS <- function() {
# only information given is what is currently operating and what is under
# construction (without start date)
x <- read_xlsx("nuclear_capacities_20240716.xlsx") %>%
mutate("operational" = operational,
"construction" = construction,
x <- readxl::read_xlsx("nuclear_capacities_20240716.xlsx") %>%
mutate("operational" = .data$operational,
"construction" = .data$construction,
variable = "Cap|Electricity|Nuclear") %>%
mutate(year = "y2020") %>% # technically, its 2024
pivot_longer(cols = c("operational", "construction"),
names_to = "status") %>%
select(country, year, variable, status, unit, value) %>%
select("country", "year", "variable", "status", "unit", "value") %>%
as.magpie(spatial = "country", temporal = "year") %>%
add_dimension(dim = 3.1, add = "model", nm = "IEA_PRIS")

# move "construction" values to year 2030
x <- add_columns(x, addnm = c("y2030"), dim = 2, fill= NA)
x <- add_columns(x, addnm = c("y2030"), dim = 2, fill = NA)

x[, 2030, "construction"] <- x[, 2020, "construction"]
x[, 2020, "construction"] <- 0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRat REMIND Input Data Package

R package **mrremind**, version **0.192.6**
R package **mrremind**, version **0.192.7**

[![CRAN status](https://www.r-pkg.org/badges/version/mrremind)](https://cran.r-project.org/package=mrremind) [![R build status](https://github.com/pik-piam/mrremind/workflows/check/badge.svg)](https://github.com/pik-piam/mrremind/actions) [![codecov](https://codecov.io/gh/pik-piam/mrremind/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po

To cite package **mrremind** in publications use:

Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.192.6, <https://github.com/pik-piam/mrremind>.
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.192.7, <https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrremind: MadRat REMIND Input Data Package},
author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux and Johannes Koch},
year = {2024},
note = {R package version 0.192.6},
note = {R package version 0.192.7},
url = {https://github.com/pik-piam/mrremind},
}
```
8 changes: 4 additions & 4 deletions man/fullThresholds.Rd → man/fullTHRESHOLDS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading