summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DESCRIPTION2
-rw-r--r--NEWS.md2
-rw-r--r--R/PEC_sw_drift.R25
-rw-r--r--log/check.log34
-rw-r--r--log/test.log6
-rw-r--r--man/PEC_sw_drift.Rd4
6 files changed, 44 insertions, 29 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index a266b0c..696eb3e 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,7 +2,7 @@ Package: pfm
Type: Package
Title: Utilities for Pesticide Fate Modelling
Version: 0.6.5
-Date: 2026-02-13
+Date: 2026-06-22
Authors@R: c(
person("Johannes Ranke", email = "johannes.ranke@agroscope.admin.ch",
role = c("aut", "cre"),
diff --git a/NEWS.md b/NEWS.md
index 41a3da7..516ac58 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,7 @@
## version 0.6.5
+- R/PEC_sw_drift.R: Support specifying units for distances and widths using the units package.
+- R/TOXSWA_cwa.R: Adapt to readr (>= 2.2.0) requiring to wrap literal input as used for reading .out files with I().
- R/PEC_sw_drainage_UK.R: Create a function `drainage_date_UK` that does not only respect the beginning of the drainage period on 1 October, but also the end of the drainage period on 30 April, and use it for determining the degradation time. Applications early in the year before 1 May will now correctly be calculated without degradation time.
- R/PEC_sw_drift.R: Vectorise the function not only with respect to distances, rates and water depths, but also with respect to crop groups. Closes issue #2 reported by Julian Klein (@juklei).
diff --git a/R/PEC_sw_drift.R b/R/PEC_sw_drift.R
index 05f90dd..621a0b6 100644
--- a/R/PEC_sw_drift.R
+++ b/R/PEC_sw_drift.R
@@ -40,7 +40,7 @@ utils::globalVariables(c("A", "B", "C", "D", "H", "hinge", "z1", "z2", "distance
#' @importFrom dplyr bind_rows
#' @importFrom tidyr pivot_longer
#' @return A numeric vector with the predicted concentration in surface water.
-#' In some cases, the vector is named with distances or drift percentages, for
+#' In some cases, the vector is named with distances or drift percentages, for
#' backward compatibility with versions before the vectorisation of arguments
#' other than 'distances' was introduced in v0.6.5.
#' @export
@@ -54,6 +54,10 @@ utils::globalVariables(c("A", "B", "C", "D", "H", "hinge", "z1", "z2", "distance
#' # This makes it possible to also use different distances
#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF")
#'
+#' # We can also specify distance units explicitly
+#' library(units)
+#' PEC_sw_drift(100, distances = set_units(c(1, 3, 5, 6, 10, 20, 50, 100), "m"), drift_data = "RF")
+#'
#' # or consider aerial application
#' PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
#' crop_group_RF = "aerial")
@@ -115,6 +119,7 @@ PEC_sw_drift <- function(rate,
rate_units <- match.arg(rate_units)
PEC_units <- match.arg(PEC_units)
if (!inherits(rate, "units")) rate <- set_units(rate, rate_units, mode = "symbolic")
+ if (!inherits(distances, "units")) distances <- set_units(distances, "m")
if (!inherits(water_width, "units")) water_width <- set_units(water_width, "cm")
if (!inherits(water_depth, "units")) water_depth <- set_units(water_depth, "cm")
drift_data <- match.arg(drift_data)
@@ -143,17 +148,17 @@ PEC_sw_drift <- function(rate,
else water_width - (water_depth / tanpi(side_angle/180))
if (as.numeric(mean_water_width) < 0) stop("Undefined geometry")
relative_mean_water_width <- mean_water_width / water_width # Always <= 1
-
+
# Check lengths of arguments advertised as vectorised for compatibility
arg_lengths <- sapply(
- list(rate = rate, applications = applications, distances = distances,
- water_depth = water_depth, crop_group_JKI = crop_group_JKI,
+ list(rate = rate, applications = applications, distances = distances,
+ water_depth = water_depth, crop_group_JKI = crop_group_JKI,
crop_group_RF = crop_group_RF),
length)
-
+
arg_lengths_not_one <- arg_lengths[arg_lengths != 1]
if (length(unique(arg_lengths_not_one)) > 1) {
- stop("The following argument lengths do not match:\n",
+ stop("The following argument lengths do not match:\n",
capture_output(print(arg_lengths_not_one)))
}
@@ -173,13 +178,13 @@ PEC_sw_drift <- function(rate,
) |>
left_join(drift_data_JKI_long, by = c("applications", "distance", "crop_group_JKI")) |>
pull(pctg)
- names(drift_percentages) <- paste(distances, "m")
+ names(drift_percentages) <- paste(as.character(distances), "m")
}
if (drift_data == "RF") {
drift_percentages <- drift_percentages_rautmann(distances, applications,
formula = formula,
crop_group_RF, widths = as.numeric(set_units(water_width, "m")))
- names(drift_percentages) <- paste(distances, "m")
+ names(drift_percentages) <- paste(as.character(distances), "m")
}
} else {
names(drift_percentages) <- paste(drift_percentages, "%")
@@ -250,9 +255,13 @@ drift_percentages_rautmann <- function(distances, applications = 1,
)
{
unmatched_crop_groups <- setdiff(crop_group_RF, unique(pfm::drift_parameters_focus$crop_group))
+ if (!inherits(distances, "units")) distances <- set_units(distances, "m")
+ if (!inherits(widths, "units")) widths <- set_units(widths, "m")
if (length(unmatched_crop_groups) > 0) stop("Crop group(s) ", unmatched_crop_groups, " not supported")
if (!all(applications %in% 1:8)) stop("Only 1 to 8 applications are supported")
formula <- match.arg(formula)
+ distances <- drop_units(distances)
+ widths <- drop_units(widths)
# To avoid recycling of components with length != 1 but smaller than the longest argument,
# which would likely be unintended, we use tibble here
diff --git a/log/check.log b/log/check.log
index 6b8ff0b..3c0c083 100644
--- a/log/check.log
+++ b/log/check.log
@@ -1,20 +1,18 @@
-* using log directory ‘/home/jranke/git/pfm/pfm.Rcheck’
-* using R version 4.5.2 (2025-10-31)
+* using log directory ‘/home/f80868656/projects/pfm/pfm.Rcheck’
+* using R version 4.6.0 (2026-04-24)
* using platform: x86_64-pc-linux-gnu
* R was compiled by
- gcc (Debian 14.2.0-19) 14.2.0
- GNU Fortran (Debian 14.2.0-19) 14.2.0
-* running under: Debian GNU/Linux 13 (trixie)
+ gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
+ GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
+* running under: Ubuntu 24.04.4 LTS
* using session charset: UTF-8
+* current time: 2026-06-22 16:48:14 UTC
* using options ‘--no-tests --as-cran’
* checking for file ‘pfm/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘pfm’ version ‘0.6.5’
* package encoding: UTF-8
-* checking CRAN incoming feasibility ... NOTE
-Maintainer: ‘Johannes Ranke <johannes.ranke@agroscope.admin.ch>’
-
-Size of tarball: 8535898 bytes
+* checking CRAN incoming feasibility ... OK
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
@@ -25,12 +23,11 @@ Size of tarball: 8535898 bytes
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘pfm’ can be installed ... OK
* checking installed package size ... INFO
- installed size is 10.3Mb
+ installed size is 10.4Mb
sub-directories of 1Mb or more:
- testdata 9.9Mb
+ testdata 10.0Mb
* checking package directory ... OK
-* checking for future file timestamps ... NOTE
-unable to verify current time
+* checking for future file timestamps ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
@@ -63,17 +60,20 @@ unable to verify current time
* checking data for non-ASCII characters ... OK
* checking LazyData ... OK
* checking data for ASCII and uncompressed saves ... OK
-* checking examples ... OK
+* checking examples ... [11s/10s] OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ... SKIPPED
* checking PDF version of manual ... OK
-* checking HTML version of manual ... OK
+* checking HTML version of manual ... NOTE
+Skipping checking HTML validation: no command 'tidy' found.
+Please obtain a recent version of HTML Tidy by downloading a binary
+release or compiling the source code from <https://www.html-tidy.org/>.
* checking for non-standard things in the check directory ... OK
* checking for detritus in the temp directory ... OK
* DONE
-Status: 2 NOTEs
+Status: 1 NOTE
See
- ‘/home/jranke/git/pfm/pfm.Rcheck/00check.log’
+ ‘/home/f80868656/projects/pfm/pfm.Rcheck/00check.log’
for details.
diff --git a/log/test.log b/log/test.log
index c2a6fc7..30b8fa9 100644
--- a/log/test.log
+++ b/log/test.log
@@ -2,17 +2,17 @@
✔ | F W S OK | Context
✔ | 7 | Exposit calculations
✔ | 6 | Geometric mean calculation
-✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions
+✔ | 1 | Check max_twa for parent mkinfit models against analytical solutions [1.0s]
✔ | 1 | Simple PEC sediment calculations
✔ | 17 | Simple PEC soil calculations
✔ | 11 | Simple PEC surface water calculations with drift entry
✔ | 1 | Actual and time weighted average concentrations for SFO kinetics
✔ | 9 | FOCUS Step 1 calculations
✔ | 8 | FOCUS Steps 12 input files
-✔ | 7 | Read and analyse TOXSWA cwa files [4.4s]
+✔ | 7 | Read and analyse TOXSWA cwa files [4.6s]
✔ | 18 | UK drainage PEC calculations
══ Results ═════════════════════════════════════════════════════════════════════════════════════════
-Duration: 6.3 s
+Duration: 6.5 s
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 86 ]
diff --git a/man/PEC_sw_drift.Rd b/man/PEC_sw_drift.Rd
index 89919bb..6774ba7 100644
--- a/man/PEC_sw_drift.Rd
+++ b/man/PEC_sw_drift.Rd
@@ -90,6 +90,10 @@ PEC_sw_drift(100, drift_data = "RF")
# This makes it possible to also use different distances
PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF")
+# We can also specify distance units explicitly
+library(units)
+PEC_sw_drift(100, distances = set_units(c(1, 3, 5, 6, 10, 20, 50, 100), "m"), drift_data = "RF")
+
# or consider aerial application
PEC_sw_drift(100, distances = c(1, 3, 5, 6, 10, 20, 50, 100), drift_data = "RF",
crop_group_RF = "aerial")

Contact - Imprint