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

in readCheckScenarioConfig, don't ask user to ignore unknown columns if failing anyway #1378

Merged
merged 1 commit into from
Aug 15, 2023
Merged
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
34 changes: 19 additions & 15 deletions scripts/start/readCheckScenarioConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,6 @@ readCheckScenarioConfig <- function(filename, remindPath = ".", testmode = FALSE
}
unknownColumnNames <- names(scenConf)[! names(scenConf) %in% knownColumnNames]
if (length(unknownColumnNames) > 0) {
message("\nAutomated checks did not find counterparts in main.gms and default.cfg for these columns in ",
basename(filename), ":")
message(" ", paste(unknownColumnNames, collapse = ", "))
message("This check was added Jan. 2022. ",
"If you find false positives, add them to knownColumnNames in start/scripts/readCheckScenarioConfig.R.\n")
unknownColumnNamesNoComments <- unknownColumnNames[! grepl("^\\.", unknownColumnNames)]
if (length(unknownColumnNamesNoComments) > 0) {
if (testmode) {
warning("Unknown column names: ", paste(unknownColumnNamesNoComments, collapse = ", "))
} else {
message("Do you want to continue and simply ignore them? Y/n")
userinput <- tolower(gms::getLine())
if (! userinput %in% c("y", "")) stop("Ok, so let's stop.")
}
}
forbiddenColumnNames <- list( # specify forbidden column name and what should be done with it
"c_budgetCO2" = "Rename to c_budgetCO2from2020, adapt emission budgets, see https://github.com/remindmodel/remind/pull/640",
"c_budgetCO2FFI" = "Rename to c_budgetCO2from2020FFI, adapt emission budgets, see https://github.com/remindmodel/remind/pull/640",
Expand Down Expand Up @@ -158,6 +143,25 @@ readCheckScenarioConfig <- function(filename, remindPath = ".", testmode = FALSE
warning("Outdated column names found that must not be used.")
errorsfound <- errorsfound + length(intersect(names(forbiddenColumnNames), unknownColumnNames))
}
# sort out known but forbidden names from unknown
unknownColumnNames <- setdiff(unknownColumnNames, names(forbiddenColumnNames))
if (length(unknownColumnNames) > 0) {
message("\nAutomated checks did not find counterparts in main.gms and default.cfg for these columns in ",
basename(filename), ":")
message(" ", paste(unknownColumnNames, collapse = ", "))
message("This check was added Jan. 2022. ",
"If you find false positives, add them to knownColumnNames in start/scripts/readCheckScenarioConfig.R.\n")
unknownColumnNamesNoComments <- unknownColumnNames[! grepl("^\\.", unknownColumnNames)]
if (length(unknownColumnNamesNoComments) > 0) {
if (testmode) {
warning("Unknown column names: ", paste(unknownColumnNamesNoComments, collapse = ", "))
} else if (errorsfound == 0) {
message("Do you want to continue and simply ignore them? Y/n")
userinput <- tolower(gms::getLine())
if (! userinput %in% c("y", "")) stop("Ok, so let's stop.")
}
}
}
}
if (errorsfound > 0) {
if (testmode) warning(errorsfound, " errors found.")
Expand Down
Loading