From d4ff20868a5e09688e3360a7243d3f148dc83168 Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 10 Jul 2024 10:28:41 +0200 Subject: [PATCH] Fix reading HYDRUS1D.DAT --- R/read_write_hydrus1d_dat.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/read_write_hydrus1d_dat.R b/R/read_write_hydrus1d_dat.R index 935cc5e..cca101a 100644 --- a/R/read_write_hydrus1d_dat.R +++ b/R/read_write_hydrus1d_dat.R @@ -15,7 +15,7 @@ read_hydrus1d <- function(path = system.file("extdata/model/test/HYDRUS1D.dat", section_start_idx <- which(stringr::str_detect(lines, "\\[")) - section_end_idx <- c(max(section_start_idx) - 4, length(lines)) + section_end_idx <- c(max(section_start_idx) - 2, length(lines)) section_names <- stringr::str_remove_all(lines[section_start_idx], "\\[|\\]") @@ -31,13 +31,18 @@ read_hydrus1d <- function(path = system.file("extdata/model/test/HYDRUS1D.dat", } - setNames(lapply(seq_len(length(section_names)), function(i) { + res <- setNames(lapply(seq_len(length(section_names)), function(i) { - mat_data <- stringr::str_split_fixed(lines[(section_start_idx[i]+1):section_end_idx[i]], pattern = "=", n = 2) + mat_data <- stringr::str_split_fixed(lines[(section_start_idx[i]+1):section_end_idx[i]], + pattern = "=", + n = 2) setNames(lapply(mat_data[, 2], convert_to_numeric), mat_data[, 1]) }), nm = section_names) + res$Profile$ProfileDepth <- toupper(format(res$Profile$ProfileDepth, + scientific = TRUE, + digits = 1)) }