Skip to content

Commit

Permalink
remove := operator from mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Jul 22, 2024
1 parent 8db99f2 commit 5065918
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 37 deletions.
6 changes: 3 additions & 3 deletions R/calcAGEB.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ calcAGEB <- function(subtype = "balances") {
ageb <- readSource("AGEB", subtype = subtype)

mapping <- toolGetMapping("Mapping_AGEB_REMIND.csv", type = "reportingVariables", where = "mappingfolder") %>%
mutate(!!sym("conversion") := as.numeric(!!sym("Factor")) * !!sym("Weight")) %>%
mutate("conversion" = as.numeric(!!sym("Factor")) * !!sym("Weight")) %>%
select("variable" = "AGEB_variable", "REMIND_variable", "conversion", "unit" = "Unit_AGEB", "Unit_REMIND") %>%
filter(!!sym("REMIND_variable") != "")

Expand All @@ -32,8 +32,8 @@ calcAGEB <- function(subtype = "balances") {
by = "variable"
) %>%
mutate(
!!sym("value") := !!sym("value") * !!sym("conversion"),
!!sym("REMIND_variable") := paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")
"value" = !!sym("value") * !!sym("conversion"),
"REMIND_variable" = paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")
) %>%
select("variable" = "REMIND_variable", "region", "year", "value")

Expand Down
2 changes: 1 addition & 1 deletion R/calcEuropeanEnergyDatasheets.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ calcEuropeanEnergyDatasheets <- function(subtype) {
mapping <- toolGetMapping("Mapping_EuropeanEnergyDatasheets.csv", type = "reportingVariables",
where = "mrremind") %>%
filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>%
mutate(!!sym("Conversion") := as.numeric(!!sym("Conversion"))) %>%
mutate("Conversion" = as.numeric(.data$Conversion)) %>%
select("variable" = "EED", "REMIND", "Conversion")

mapping$variable <- trimws(mapping$variable)
Expand Down
10 changes: 5 additions & 5 deletions R/calcIEA_ETP.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ calcIEA_ETP <- function() {

mapping <- toolGetMapping("Mapping_IEA_ETP.csv", type = "reportingVariables", where = "mrremind") %>%
filter(!is.na(!!sym("REMIND")), !!sym("REMIND") != "") %>%
mutate(!!sym("Conversion") := as.numeric(!!sym("Conversion"))) %>%
mutate("Conversion" = as.numeric(!!sym("Conversion"))) %>%
select("variable" = "IEA_ETP", "REMIND", "Conversion", "Unit_REMIND")

mapping$variable <- trimws(mapping$variable)
Expand Down Expand Up @@ -42,10 +42,10 @@ calcIEA_ETP <- function() {
) %>%
filter(!!sym("REMIND") != "") %>%
mutate(
!!sym("value") := !!sym("value") * !!sym("Conversion"),
!!sym("REMIND") := paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")"),
!!sym("model") := paste0("IEA ETP ", !!sym("scenario")),
!!sym("year") := as.numeric(as.character(!!sym("year")))
"value" = !!sym("value") * !!sym("Conversion"),
"REMIND" = paste0(!!sym("REMIND"), " (", !!sym("Unit_REMIND"), ")"),
"model" = paste0("IEA ETP ", !!sym("scenario")),
"year" = as.numeric(as.character(!!sym("year")))
) %>%
select("region", "year", "model", "variable" = "REMIND", "value")

Expand Down
4 changes: 1 addition & 3 deletions R/calcUBA.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ calcUBA <- function() {
mapping,
by = "variable"
) %>%
mutate(
!!sym("REMIND_variable") := paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")
) %>%
mutate("REMIND_variable" = paste0(!!sym("REMIND_variable"), " (", !!sym("Unit_REMIND"), ")")) %>%
select("variable" = "REMIND_variable", "region", "year", "value")

x <- aggregate(value ~ variable + region + year, x, sum) %>%
Expand Down
6 changes: 2 additions & 4 deletions R/convertEuropeanEnergyDatasheets.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ convertEuropeanEnergyDatasheets <- function(x, subtype) {
getItems(x, dim = 1) <- sapply(getRegions(x), function(y) iso3[which(iso3[, 1] == y), 2])

# fill up zero countries
x <- toolCountryFill(x, fill = NA, verbosity = 2)

# fill smaller EU-countries with 0s to allow for aggregation of EU-region
x[c("ALA", "FRO", "GIB", "GGY", "IMN", "JEY"), , ] <- 0
x <- toolCountryFill(x, fill = NA, verbosity = 2) %>%
toolFillEU34Countries()

# in never mapping, this is handled directly in mapping
if (subtype == "EU28") {
Expand Down
2 changes: 1 addition & 1 deletion R/convertMueller.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ convertMueller <- function(x, subtype) {
if (subtype == "stocks") {
x %>%
madrat_mule() %>%
mutate(!!sym("variable") := paste0("Steel stock per-capita|", !!sym("estimate"), " (t)")) %>%
mutate("variable" = paste0("Steel stock per-capita|", !!sym("estimate"), " (t)")) %>%
select("region" = "iso3c", "period" = "year", "variable", "value" = "steel.stock.per.capita") %>%
as.magpie() %>%
toolCountryFill(fill = 0, verbosity = 2, no_remove_warning = c("ANT")) %>%
Expand Down
12 changes: 6 additions & 6 deletions R/readAGEB.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ readAGEB <- function(subtype = "balances") {
)
) %>%
filter(!is.na(!!sym("Einheit"))) %>%
mutate(!!sym("Energietraeger") := paste0(sheets[["name"]][[i]], "|", !!sym("Energietr\u00E4ger"))) %>%
mutate("Energietraeger" = paste0(sheets[["name"]][[i]], "|", !!sym("Energietr\u00E4ger"))) %>%
select(-1)

data <- bind_rows(data, tmp)
Expand All @@ -87,13 +87,13 @@ readAGEB <- function(subtype = "balances") {
col_types = c("text", rep("numeric", 32)),
range = "B3:AH17", .name_repair = "minimal", na = c("k.A.")
) %>%
mutate(!!sym("TWh") := gsub(", darunter:", "", !!sym("TWh"))) %>%
mutate(!!sym("TWh") := gsub("- ", "", !!sym("TWh"))) %>%
mutate(!!sym("TWh") := gsub("[0-9])", "", !!sym("TWh"))) %>%
mutate(!!sym("variable") := paste0("9 Bruttostromerzeugung|", !!sym("TWh"))) %>%
mutate("TWh" = gsub(", darunter:", "", !!sym("TWh"))) %>%
mutate("TWh" = gsub("- ", "", !!sym("TWh"))) %>%
mutate("TWh" = gsub("[0-9])", "", !!sym("TWh"))) %>%
mutate("variable" = paste0("9 Bruttostromerzeugung|", !!sym("TWh"))) %>%
select(-1) %>%
reshape2::melt(id.vars = c("variable"), variable.name = "period", value.name = "value") %>%
mutate(!!sym("region") := "DEU", !!sym("unit") := "TWh") %>%
mutate("region" = "DEU", "unit" = "TWh") %>%
select("region", "period", "variable", "unit", "value") %>%
as.magpie() %>%
return()
Expand Down
6 changes: 3 additions & 3 deletions R/readEuropeanEnergyDatasheets.R
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ readEuropeanEnergyDatasheets <- function(subtype) {
select(-1) %>%
reshape2::melt(id.vars = c("variable", "unit"), variable.name = "year") %>%
mutate(
"year" := as.numeric(as.character(.data$year)),
"region" := sheet,
"value" := suppressWarnings(as.numeric(.data$value))
"year" = as.numeric(as.character(.data$year)),
"region" = sheet,
"value" = suppressWarnings(as.numeric(.data$value))
)
)
}
Expand Down
10 changes: 5 additions & 5 deletions R/readGlobalEnergyMonitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ readGlobalEnergyMonitor <- function() {
) %>%
select(all_of(cols)) %>%
mutate(
!!sym("value") := as.numeric(!!sym("value")),
!!sym("start") := as.numeric(!!sym("start")),
!!sym("end") := as.numeric(!!sym("end"))
"value" = as.numeric(!!sym("value")),
"start" = as.numeric(!!sym("start")),
"end" = as.numeric(!!sym("end"))
)

if (!is.null(nb$typeCol)) {
Expand All @@ -102,7 +102,7 @@ readGlobalEnergyMonitor <- function() {
!is.na(!!sym("start")), is.na(!!sym("end")),
!!sym("status") %in% status
) %>%
mutate(!!sym("end") := 2050)
mutate("end" = 2050)

production <- rbind(completed, ongoing)
tmp <- NULL
Expand All @@ -114,7 +114,7 @@ readGlobalEnergyMonitor <- function() {
tmp <- rbind(tmp, d)
}
cap <- aggregate(value ~ region + period, data = tmp, FUN = sum) %>%
mutate(!!sym("variable") := nb$variable) %>%
mutate("variable" = nb$variable) %>%
select("region", "period", "variable", "value")

out <- rbind(out, cap)
Expand Down
4 changes: 2 additions & 2 deletions R/readIEA_ETP.R
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ readIEA_ETP <- function(subtype) {
# drop rownames from worksheet
select(-1) %>%
# add variable prefix
mutate(variable = paste0(subtypes[[subtype]]$prefix, "|", !!sym("variable"))) %>%
mutate("variable" = paste0(subtypes[[subtype]]$prefix, "|", !!sym("variable"))) %>%
pivot_longer(
cols = c(-"variable", -"unit"), names_to = "year",
names_transform = list("year" = as.integer)
) %>%
mutate(region := sheet, scenario := scenario)
mutate("region" = sheet, "scenario" = scenario)
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/readIRENA.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ readIRENA <- function(subtype) {
id.vars = c(1, 2),
variable.name = "years", value.name = "value"
) %>%
mutate(!!sym("value") := as.numeric(!!sym("value"))) %>%
mutate("value" = as.numeric(!!sym("value"))) %>%
suppressWarnings()

# rearrange column order to more readable format: year, country, tech, value (capacity or generation)
Expand Down
4 changes: 2 additions & 2 deletions R/readUNFCCC.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ readUNFCCC <- function() {
filter(!is.na(!!sym("name"))) %>%
reshape2::melt(id.vars = c("name", "region", "year")) %>%
mutate(
!!sym("value") := suppressWarnings(as.double(!!sym("value"))),
!!sym("name") := paste0(sub("\\.", "_", i), "|", !!sym("name"), "|", sub(".+ ", "", !!sym("variable")))
"value" = suppressWarnings(as.double(!!sym("value"))),
"name" = paste0(sub("\\.", "_", i), "|", !!sym("name"), "|", sub(".+ ", "", !!sym("variable")))
) %>%
select(-"name", "unit" = "variable", "variable" = "name") %>%
filter(!is.na(!!sym("value")))
Expand Down
2 changes: 1 addition & 1 deletion R/toolFillEU34Countries.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Sets values for 6 EU countries not belonging to EU 28 but EU 34 to zero if
#' they are NA. Used to avoid EUR region not yielding NA because of these countries.
#' they are NA. Used to avoid EUR region yielding NA because of these countries.
#'
#' @param x magpie object with 249 ISO country codes in the spatial dimension
#' @author Falk Benke
Expand Down

0 comments on commit 5065918

Please sign in to comment.