aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-03-01 16:59:30 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-03-01 17:56:11 +0100
commit1ba0938b5a39f9d376b54fe3469b40aafea9e8e3 (patch)
tree4e7e67855246d59a04d2eb0f18646fcc9460e020
parentccae8c02b1e6a30911b9d1efdb388f30f9c9cb78 (diff)
Avoid using cat() for default output, tests
-rw-r--r--R/f_time_norm_focus.R3
-rw-r--r--R/mkinfit.R4
-rw-r--r--test.log26
-rw-r--r--tests/testthat/test_f_time_norm.R7
-rw-r--r--tests/testthat/test_mkinfit.R10
5 files changed, 29 insertions, 21 deletions
diff --git a/R/f_time_norm_focus.R b/R/f_time_norm_focus.R
index e7c6f22e..259dd131 100644
--- a/R/f_time_norm_focus.R
+++ b/R/f_time_norm_focus.R
@@ -107,7 +107,6 @@ f_time_norm_focus.mkindsg <- function(object,
object$f_time_norm <- f_time_norm_focus(meta$temperature,
moisture = study_moisture, field_moisture = field_moisture,
Q10 = Q10, walker = walker, f_na = f_na)
- cat("$time_norm was set to\n")
- print(object$f_time_norm)
+ message("$f_time_norm was (re)set to normalised values")
invisible(object$f_time_norm)
}
diff --git a/R/mkinfit.R b/R/mkinfit.R
index 4da39841..bf164c3f 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -646,8 +646,8 @@ mkinfit <- function(mkinmod, observed,
if (cost < cost.current) {
assign("cost.current", cost, inherits = TRUE)
- if (!quiet) cat(ifelse(OLS, "Sum of squared residuals", "Negative log-likelihood"),
- " at call ", calls, ": ", signif(cost.current, 6), "\n", sep = "")
+ if (!quiet) message(ifelse(OLS, "Sum of squared residuals", "Negative log-likelihood"),
+ " at call ", calls, ": ", signif(cost.current, 6), "\n")
}
}
return(cost)
diff --git a/test.log b/test.log
index b044e6a0..a2217f49 100644
--- a/test.log
+++ b/test.log
@@ -3,22 +3,22 @@ Loading required package: parallel
ℹ Testing mkin
✔ | F W S OK | Context
✔ | 5 | AIC calculation
-✔ | 5 | Analytical solutions for coupled models [4.3s]
+✔ | 5 | Analytical solutions for coupled models [4.4s]
✔ | 5 | Calculation of Akaike weights
✔ | 2 | Export dataset for reading into CAKE
-✔ | 12 | Confidence intervals and p-values [1.1s]
+✔ | 12 | Confidence intervals and p-values [1.0s]
⠋ | 1 | Dimethenamid data from 2018
-✔ | 1 25 | Dimethenamid data from 2018 [49.7s]
+✔ | 1 25 | Dimethenamid data from 2018 [49.4s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_dmta.R:147:3): Different backends get consistent results for SFO-SFO3+, dimethenamid data
Reason: Fitting this ODE model with saemix takes about 15 minutes on my system
────────────────────────────────────────────────────────────────────────────────
-✔ | 14 | Error model fitting [7.0s]
+✔ | 14 | Error model fitting [6.9s]
✔ | 5 | Time step normalisation
✔ | 4 | Calculation of FOCUS chi2 error levels [0.8s]
-✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.1s]
-✔ | 4 | Test fitting the decline of metabolites from their maximum [0.5s]
-✔ | 1 | Fitting the logistic model [0.3s]
+✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.2s]
+✔ | 4 | Test fitting the decline of metabolites from their maximum [0.6s]
+✔ | 1 | Fitting the logistic model [0.4s]
⠴ | 6 | Nonlinear mixed-effects models
✔ | 1 15 | Nonlinear mixed-effects models [2.4s]
────────────────────────────────────────────────────────────────────────────────
@@ -27,16 +27,16 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve
────────────────────────────────────────────────────────────────────────────────
✔ | 3 | Test dataset classes mkinds and mkindsg
✔ | 10 | Special cases of mkinfit calls [0.6s]
-✔ | 1 | mkinfit features [0.5s]
+✔ | 3 | mkinfit features [1.1s]
✔ | 8 | mkinmod model generation and printing [0.2s]
-✔ | 3 | Model predictions with mkinpredict [0.4s]
+✔ | 3 | Model predictions with mkinpredict [0.3s]
✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.1s]
✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s]
✔ | 16 | Plotting [1.5s]
✔ | 4 | Residuals extracted from mkinfit models
-✔ | 23 | saemix_parent [30.4s]
+✔ | 23 | saemix_parent [29.2s]
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.6s]
-✔ | 7 | Fitting the SFORB model [4.5s]
+✔ | 7 | Fitting the SFORB model [4.4s]
✔ | 1 | Summaries of old mkinfit objects
✔ | 4 | Summary [0.1s]
✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.6s]
@@ -44,10 +44,10 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 133.2 s
+Duration: 132.0 s
── Skipped tests ──────────────────────────────────────────────────────────────
• Fitting this ODE model with saemix takes about 15 minutes on my system (1)
• Fitting with saemix takes around 10 minutes when using deSolve (1)
-[ FAIL 0 | WARN 0 | SKIP 2 | PASS 235 ]
+[ FAIL 0 | WARN 0 | SKIP 2 | PASS 237 ]
diff --git a/tests/testthat/test_f_time_norm.R b/tests/testthat/test_f_time_norm.R
index c5e0607c..d5b89902 100644
--- a/tests/testthat/test_f_time_norm.R
+++ b/tests/testthat/test_f_time_norm.R
@@ -5,13 +5,12 @@ test_that("Simple temperature and moisture normalisation works", {
})
test_that("Time step normalisation for a dataset works", {
- expect_output(f_time_norm_focus(D24_2014, study_moisture_ref_source = "focus", f_na = 1),
- "was set to")
+ expect_message(f_time_norm_focus(D24_2014, study_moisture_ref_source = "focus", f_na = 1))
expect_equal(round(D24_2014$f_time_norm, 3), c(1.606, 0.712, 0.716, 0.716, 0.898))
- expect_output(f_time_norm_focus(dimethenamid_2018), "was set to")
+ expect_message(f_time_norm_focus(dimethenamid_2018))
# Reference values from Dimethenamid RAR 2018 Vol3 B.8
- expect_equal(round(dimethenamid_2018$f_time_norm, 3),
+ expect_equal(round(dimethenamid_2018$f_time_norm, 3),
c(1,
0.971, # p. 56
rep(round(1.329 * 0.924, 3), 2), # p. 51
diff --git a/tests/testthat/test_mkinfit.R b/tests/testthat/test_mkinfit.R
index fb81c3d8..11b6111a 100644
--- a/tests/testthat/test_mkinfit.R
+++ b/tests/testthat/test_mkinfit.R
@@ -8,3 +8,13 @@ test_that("Specifying initial values for state variables works correctly", {
# also affecting AIC calculations
expect_equal(logLik(f_1), logLik(f_2))
})
+
+test_that("We get messages and output from mkinfit if desired", {
+ # For progress info we use message()
+ expect_message(mkinfit("SFO", FOCUS_2006_A, quiet = FALSE))
+
+ # trace_parms uses cat()
+ out <- capture.output(
+ tmp <- mkinfit("SFO", FOCUS_2006_A, trace_parms = TRUE, quiet = TRUE))
+ expect_true(length(out) > 10)
+})

Contact - Imprint