From 8aa5271312a08238e0b879496142c06f30e8a58c Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 10 Jul 2024 10:07:23 +0200 Subject: [PATCH] Fix read_profile() for obsnodes! --- R/read_profile.R | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/R/read_profile.R b/R/read_profile.R index 974057b..dd6509e 100644 --- a/R/read_profile.R +++ b/R/read_profile.R @@ -62,16 +62,19 @@ read_profile <- function(path) { if (length(which(ncols == 2)) > 0) { idx_obsnodes <- which(ncols == 2) - if(any(idx_obsnodes < length(ncols))) { + obsnodes$n <- as.integer(dat[idx_obsnodes[1]]) - n_obsnodes <- as.integer(dat[idx_obsnodes[-length(idx_obsnodes)]]) - obs_node_ids <- stringr::str_split(dat[idx_obsnodes[length(idx_obsnodes)]], + if(stringr::str_length(dat[idx_obsnodes[1]+1]) > 0) { + + obsnodes$ids <- stringr::str_split(dat[idx_obsnodes[1]+1], pattern = ",", simplify = TRUE) %>% as.integer() - obsnodes <- list(n = n_obsnodes, - ids = obs_node_ids) + } else { + stop("Check stucture of input file %s. Missing ids for %d specified observation points!", + path, + obsnodes$n) } }