Skip to content

Commit

Permalink
don't overwrite json for models.json
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Nov 11, 2024
1 parent 8e5c908 commit c8a5647
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions R/WriteModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ writeModelMetadata <- function(model, dirs, to_format="csv") {
package="useeior"))

# Write model description to models.csv
model_desc <- file.path(dirs$data, "models.csv")
model_desc <- file.path(dirs$data, paste0("models.", to_format))
ID <- model$specs$Model
Name <- model$specs$Model
Location <- model$specs$ModelRegionAcronyms[1]
Expand All @@ -262,8 +262,12 @@ writeModelMetadata <- function(model, dirs, to_format="csv") {
if (!file.exists(model_desc)) {
df <- cbind.data.frame(model_fields)
} else {
df <- utils::read.table(model_desc, sep = ",", header = TRUE,
stringsAsFactors = FALSE, check.names = FALSE)
if(to_format == "csv") {
df <- utils::read.table(model_desc, sep = ",", header = TRUE,
stringsAsFactors = FALSE, check.names = FALSE)
} else if (to_format == "json") {
df <- jsonlite::fromJSON(model_desc)
}
if (!ID%in%df$ID) {
df <- rbind(df, cbind.data.frame(model_fields))
}
Expand Down

0 comments on commit c8a5647

Please sign in to comment.