From 32c0130b54c90204e48f3b8c7eeb716238f0d632 Mon Sep 17 00:00:00 2001 From: mrustl Date: Mon, 1 Jul 2024 10:44:41 +0200 Subject: [PATCH] Adapt to accept data.frame as c_tops --- R/prepare_atmosphere.R | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/R/prepare_atmosphere.R b/R/prepare_atmosphere.R index 0576c1c..b180d55 100644 --- a/R/prepare_atmosphere.R +++ b/R/prepare_atmosphere.R @@ -110,7 +110,24 @@ prepare_atmosphere <- function( conc_irrig_clearwater = conc_irrig_clearwater, conc_rain = conc_rain) - n_conc <- sapply(conc_paras, length) + + is_vector <- sapply(conc_paras, is.vector) + + n_conc <- sapply(seq_along(conc_paras), function(i) { if(is_vector[i]) { + length(conc_paras[[i]]) + } else { + if(is.data.frame(conc_paras[[i]])) { + stopifnot(nrow(conc_paras[[i]]) == nrow(atm)) + stopifnot(ncol(conc_paras[[i]]) <= 10) + ncol(conc_paras[[i]]) + } else { + stop("unsupported data type") + } + } + }) + + names(n_conc) <- names(conc_paras) + if (sum(n_conc > 1) > 1) { if(all(n_conc[n_conc > 1] != n_conc[n_conc > 1][1])) {