Skip to content

Commit

Permalink
Add further error message if project IDs are not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-z-am committed Jul 29, 2024
1 parent e2a114f commit b484e33
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/add_qsimVis_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@
add_qsimVis_id <- function(aggregated_data, translation_table){
separate_project_ids <- strsplit(x = translation_table$section_name, ",")
project_ids <- unlist(separate_project_ids)
aggregated_data$qsimVis_size <-
aggregated_data$qsimVis_source <-
aggregated_data$qsimVis_source <-
aggregated_data$qsimVis_river <- NA

for(project_id in project_ids){
df_row <- which(sapply(separate_project_ids, function(x){project_id %in% x}))
if(length(df_row) == 0L){
stop("Project ID: ", project_id, " not found in translation table")
}
if(length(df_row) > 1L){
stop("Project ID: ", project_id, " is part of two or more rivers.")
}
qsimVis_id <- translation_table[["ID"]][df_row]
qsimVis_source <- ifelse(
test = is.na(translation_table[["verknet_BWaStrIdNr"]][df_row]),
Expand All @@ -47,11 +49,12 @@ add_qsimVis_id <- function(aggregated_data, translation_table){
)
qsimVis_size <- translation_table[["river_size"]][df_row]

section_rows <- grep(pattern = project_id, x = aggregated_data$section_name)
section_rows <- grep(
pattern = paste0("^", project_id, "$") ,
x = aggregated_data$section_name
)
aggregated_data$qsimVis_river[section_rows] <- qsimVis_id
aggregated_data$qsimVis_source[section_rows] <- qsimVis_source
aggregated_data$qsimVis_size[section_rows] <- qsimVis_size

}
aggregated_data
}

0 comments on commit b484e33

Please sign in to comment.