diff options
| -rw-r--r-- | DESCRIPTION | 4 | ||||
| -rw-r--r-- | NAMESPACE | 1 | ||||
| -rw-r--r-- | R/PEC_sw_drift.R | 19 | ||||
| -rw-r--r-- | log/check.log | 22 | ||||
| -rw-r--r-- | log/test.log | 10 | ||||
| -rw-r--r-- | man/PEC_sw_drift.Rd | 5 | ||||
| -rw-r--r-- | tests/testthat/test_PEC_sw_drift.R | 4 |
7 files changed, 45 insertions, 20 deletions
diff --git a/DESCRIPTION b/DESCRIPTION index dc4d69d..1e81c59 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -17,9 +17,9 @@ Depends: R6, mkin (>= 1.2) Imports: - graphics, readr, methods, units, dplyr, tibble, tidyr + graphics, readr, methods, units, dplyr, tibble, tidyr, testthat Suggests: - testthat, chents, grImport, magrittr, covr, here, waldo, docxtractr + chents, grImport, magrittr, covr, here, waldo, docxtractr License: GPL LazyLoad: true LazyData: true @@ -66,6 +66,7 @@ importFrom(stats,plot.ts) importFrom(stats,start) importFrom(stats,time) importFrom(stats,ts) +importFrom(testthat,capture_output) importFrom(tibble,as_tibble) importFrom(tibble,tibble) importFrom(tidyr,pivot_longer) diff --git a/R/PEC_sw_drift.R b/R/PEC_sw_drift.R index cf2328a..413388c 100644 --- a/R/PEC_sw_drift.R +++ b/R/PEC_sw_drift.R @@ -12,6 +12,7 @@ utils::globalVariables(c("A", "B", "C", "D", "H", "hinge", "z1", "z2", "distance #' applications, water depth, crop groups and distances #' #' @inheritParams drift_percentages_rautmann +#' @importFrom testthat capture_output #' @importFrom units as_units set_units #' @seealso [drift_parameters_focus], [drift_percentages_rautmann] #' @param rate Application rate in units specified below, or with units defined via the @@ -38,7 +39,10 @@ utils::globalVariables(c("A", "B", "C", "D", "H", "hinge", "z1", "z2", "distance #' @importFrom tibble as_tibble #' @importFrom dplyr bind_rows #' @importFrom tidyr pivot_longer -#' @return The predicted concentration in surface water +#' @return A numeric vector with the predicted concentration in surface water. +#' 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 #' @author Johannes Ranke #' @examples @@ -135,6 +139,19 @@ 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, + 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", + capture_output(print(arg_lengths_not_one))) + } # Base PEC sw drift for overspray PEC_sw_overspray <- set_units(rate / (relative_mean_water_width * water_depth), PEC_units, mode = "symbolic") diff --git a/log/check.log b/log/check.log index 7b1b369..8dfd612 100644 --- a/log/check.log +++ b/log/check.log @@ -1,10 +1,10 @@ -* using log directory ‘/home/jranke/git/pfm/pfm.Rcheck’ +* using log directory ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck’ * using R version 4.5.2 (2025-10-31) * 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) 13.3.0 + GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 +* running under: Ubuntu 24.04.3 LTS * using session charset: UTF-8 * using options ‘--no-tests --as-cran’ * checking for file ‘pfm/DESCRIPTION’ ... OK @@ -14,7 +14,7 @@ * checking CRAN incoming feasibility ... NOTE Maintainer: ‘Johannes Ranke <johannes.ranke@agroscope.admin.ch>’ -Size of tarball: 8534968 bytes +Size of tarball: 8536724 bytes * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK @@ -29,8 +29,7 @@ Size of tarball: 8534968 bytes sub-directories of 1Mb or more: testdata 9.9Mb * 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 +62,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 ... [17s/11s] 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 See - ‘/home/jranke/git/pfm/pfm.Rcheck/00check.log’ + ‘/home/agsad.admin.ch/f80868656/projects/pfm/pfm.Rcheck/00check.log’ for details. diff --git a/log/test.log b/log/test.log index ff352bd..3b7092e 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.1s] ✔ | 1 | Simple PEC sediment calculations ✔ | 17 | Simple PEC soil calculations -✔ | 10 | Simple PEC surface water calculations with drift entry +✔ | 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.2s] +✔ | 7 | Read and analyse TOXSWA cwa files [4.8s] ✔ | 17 | UK drainage PEC calculations ══ Results ═════════════════════════════════════════════════════════════════════════════════════════ -Duration: 6.0 s +Duration: 6.9 s -[ FAIL 0 | WARN 0 | SKIP 0 | PASS 84 ] +[ FAIL 0 | WARN 0 | SKIP 0 | PASS 85 ] diff --git a/man/PEC_sw_drift.Rd b/man/PEC_sw_drift.Rd index 1cc7d4e..89919bb 100644 --- a/man/PEC_sw_drift.Rd +++ b/man/PEC_sw_drift.Rd @@ -64,7 +64,10 @@ if the specified rate does not have \link[units:units]{units::units}].} \item{PEC_units}{Requested units for the calculated PEC. Only µg/L currently supported} } \value{ -The predicted concentration in surface water +A numeric vector with the predicted concentration in surface water. +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. } \description{ This is a basic, vectorised form of a simple calculation of a contaminant diff --git a/tests/testthat/test_PEC_sw_drift.R b/tests/testthat/test_PEC_sw_drift.R index 5d343d0..da5b185 100644 --- a/tests/testthat/test_PEC_sw_drift.R +++ b/tests/testthat/test_PEC_sw_drift.R @@ -62,5 +62,7 @@ test_that("The function is vectorised also with respect to crop groups", { expect_equal( round(res_vec_2, 3), set_units(c('5 m' = 0.191, '5 m' = 0.160, '5 m' = 0.191, '5 m' = 0.095, '10 m' = 3.936, '5 m' = 6.628), "\u00B5g/L")) - + + # If different argument lengths are supplied, we should get an error + expect_error(PEC_sw_drift(c(200, 100), distances = c(1, 5, 10)), "argument lengths") }) |
