From 8fd8f9c04492cce60c1cd1e6b9a53057990ec31e Mon Sep 17 00:00:00 2001 From: Elisabeth Lutz <168072575+Lutzeli@users.noreply.github.com> Date: Thu, 5 Feb 2026 13:38:13 +0100 Subject: Add unit check for rate and set units for PEC calculation without this change PEC units will apear as [g/ha] when the rate input is given in [g/ha] --- R/PEC_sw_drainage_UK.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/PEC_sw_drainage_UK.R b/R/PEC_sw_drainage_UK.R index 4b3111e..2c7e28f 100644 --- a/R/PEC_sw_drainage_UK.R +++ b/R/PEC_sw_drainage_UK.R @@ -33,7 +33,8 @@ PEC_sw_drainage_UK <- function(rate, interception = 0, Koc, model = NULL, model_parms = NULL) { percentage_lost <- SSLRC_mobility_classification(Koc)[[2]] - amount_available <- rate * (1 - interception) # g/ha + if (inherits(rate, "units") && !identical(as.character(units(rate)), "g/ha")) stop("rate must have units g/ha, not ", units(rate)) + amount_available <- as.numeric(rate) * (1 - interception) # g/ha if (!missing(latest_application)) { lct <- Sys.getlocale("LC_TIME") @@ -62,6 +63,6 @@ PEC_sw_drainage_UK <- function(rate, interception = 0, Koc, } volume = 130000 # L/ha - PEC = 1e6 * (percentage_lost/100) * amount_available / volume + PEC = set_units(1e6 * (percentage_lost/100) * amount_available / volume, "µg/L") return(PEC) } -- cgit v1.2.3