aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-03-19 05:51:10 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-03-19 05:51:10 +0100
commitd03a6abad27d6eef13dceb64f31b1278bb816c00 (patch)
treeedb0d2ae49ce3e74167616305bab494ba7670fc1
parente48c1f2ef990a622722e416c8d301430db4f5081 (diff)
Improvements to CAKE_export()
-rw-r--r--NEWS.md2
-rw-r--r--R/CAKE_export.R11
-rw-r--r--man/CAKE_export.Rd4
-rw-r--r--test.log46
-rw-r--r--tests/testthat/FOCUS_2006_D.csf14
-rw-r--r--tests/testthat/FOCUS_2006_D.rdsbin591 -> 561 bytes
-rw-r--r--tests/testthat/test_CAKE_export.R13
7 files changed, 45 insertions, 45 deletions
diff --git a/NEWS.md b/NEWS.md
index e675fc72..1524e1cf 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,8 @@
- 'dimethenamid_2018': Update example code to use saemix
+- 'CAKE_export': Check for validity of the map argument, updates
+
# mkin 1.1.0 (2022-03-14)
## Mixed-effects models
diff --git a/R/CAKE_export.R b/R/CAKE_export.R
index 70661b10..b16f186a 100644
--- a/R/CAKE_export.R
+++ b/R/CAKE_export.R
@@ -28,11 +28,11 @@
CAKE_export <- function(ds, map = c(parent = "Parent"),
links = NA,
filename = "CAKE_export.csf", path = ".", overwrite = FALSE,
- study = "Codlemone aerobic soil degradation",
+ study = "Degradinol aerobic soil degradation",
description = "",
time_unit = "days",
res_unit = "% AR",
- comment = "Created using mkin::CAKE_export",
+ comment = "",
date = Sys.Date(),
optimiser = "IRLS")
{
@@ -41,11 +41,16 @@ CAKE_export <- function(ds, map = c(parent = "Parent"),
csf <- file(file, encoding = "latin1", open = "w+")
on.exit(close(csf))
+ CAKE_compartments = c("Parent", "A1", "A2", "A3", "B1", "B2", "C1")
+ if (!all(map %in% CAKE_compartments)) {
+ stop("The elements of map have to be CAKE compartment names")
+ }
+
add <- function(x) cat(paste0(x, "\r\n"), file = csf, append = TRUE)
add0 <- function(x) cat(x, file = csf, append = TRUE)
add("[FileInfo]")
- add("CAKE-Version: 3.3 (Release)")
+ add("CAKE-Version: 3.4 (Release)")
add(paste("Name:", study))
add(paste("Description:", description))
add(paste("MeasurementUnits:", res_unit))
diff --git a/man/CAKE_export.Rd b/man/CAKE_export.Rd
index 4bcd8581..fc0aedf5 100644
--- a/man/CAKE_export.Rd
+++ b/man/CAKE_export.Rd
@@ -11,11 +11,11 @@ CAKE_export(
filename = "CAKE_export.csf",
path = ".",
overwrite = FALSE,
- study = "Codlemone aerobic soil degradation",
+ study = "Degradinol aerobic soil degradation",
description = "",
time_unit = "days",
res_unit = "\% AR",
- comment = "Created using mkin::CAKE_export",
+ comment = "",
date = Sys.Date(),
optimiser = "IRLS"
)
diff --git a/test.log b/test.log
index cd168e7f..4c273c19 100644
--- a/test.log
+++ b/test.log
@@ -3,65 +3,49 @@ Loading required package: parallel
ℹ Testing mkin
✔ | F W S OK | Context
✔ | 5 | AIC calculation
-✔ | 5 | Analytical solutions for coupled models [3.3s]
+✔ | 5 | Analytical solutions for coupled models [3.4s]
✔ | 5 | Calculation of Akaike weights
-✔ | 2 | Export dataset for reading into CAKE
+✔ | 3 | Export dataset for reading into CAKE
✔ | 12 | Confidence intervals and p-values [1.0s]
-✔ | 1 12 | Dimethenamid data from 2018 [31.2s]
+✔ | 1 12 | Dimethenamid data from 2018 [32.7s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_dmta.R:98: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 [4.7s]
+✔ | 14 | Error model fitting [5.0s]
✔ | 5 | Time step normalisation
✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s]
✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.8s]
✔ | 4 | Test fitting the decline of metabolites from their maximum [0.3s]
✔ | 1 | Fitting the logistic model [0.2s]
-✔ | 1 12 | Nonlinear mixed-effects models [0.2s]
+✔ | 1 12 | Nonlinear mixed-effects models [0.3s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_mixed.R:68:3): saemix results are reproducible for biphasic fits
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.4s]
+✔ | 10 | Special cases of mkinfit calls [0.5s]
✔ | 3 | mkinfit features [0.7s]
✔ | 8 | mkinmod model generation and printing [0.3s]
✔ | 3 | Model predictions with mkinpredict [0.4s]
-✔ | 16 | Evaluations according to 2015 NAFTA guidance [1.5s]
-✔ | 9 | Nonlinear mixed-effects models with nlme [8.2s]
-✔ | 5 16 | Plotting [10.5s]
-────────────────────────────────────────────────────────────────────────────────
-Warning (test_plot.R:48:3): Plotting mkinfit, mmkin and mixed model objects is reproducible
-Adding new file snapshot: 'tests/testhat/_snaps/mixed-model-fit-for-mmkin-object.svg'
-
-Warning (test_plot.R:51:3): Plotting mkinfit, mmkin and mixed model objects is reproducible
-Adding new file snapshot: 'tests/testhat/_snaps/mixed-model-fit-for-saem-object-with-saemix-transformations.svg'
-
-Warning (test_plot.R:56:3): Plotting mkinfit, mmkin and mixed model objects is reproducible
-Adding new file snapshot: 'tests/testhat/_snaps/mixed-model-fit-for-nlme-object.svg'
-
-Warning (test_plot.R:64:3): Plotting mkinfit, mmkin and mixed model objects is reproducible
-Adding new file snapshot: 'tests/testhat/_snaps/mixed-model-fit-for-saem-object-with-mkin-transformations.svg'
-
-Warning (test_plot.R:68:3): Plotting mkinfit, mmkin and mixed model objects is reproducible
-Adding new file snapshot: 'tests/testhat/_snaps/plot-errmod-with-focus-d-obs-eigen.svg'
-────────────────────────────────────────────────────────────────────────────────
+✔ | 16 | Evaluations according to 2015 NAFTA guidance [1.6s]
+✔ | 9 | Nonlinear mixed-effects models with nlme [8.6s]
+✔ | 16 | Plotting [10.4s]
✔ | 4 | Residuals extracted from mkinfit models
-✔ | 23 | saemix parent models [28.9s]
-✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.5s]
-✔ | 7 | Fitting the SFORB model [3.8s]
+✔ | 23 | saemix parent models [28.0s]
+✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s]
+✔ | 7 | Fitting the SFORB model [3.7s]
✔ | 1 | Summaries of old mkinfit objects
✔ | 4 | Summary [0.1s]
✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s]
-✔ | 9 | Hypothesis tests [8.2s]
+✔ | 9 | Hypothesis tests [8.1s]
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 111.6 s
+Duration: 112.8 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 5 | SKIP 2 | PASS 221 ]
+[ FAIL 0 | WARN 0 | SKIP 2 | PASS 222 ]
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index 5969712b..180091ab 100644
--- a/tests/testthat/FOCUS_2006_D.csf
+++ b/tests/testthat/FOCUS_2006_D.csf
@@ -1,11 +1,11 @@
[FileInfo]
-CAKE-Version: 3.3 (Release)
+CAKE-Version: 3.4 (Release)
Name: FOCUS 2006 D
Description:
MeasurementUnits: % AR
TimeUnits: days
-Comments: Created using mkin::CAKE_export
-Date: Dummy date 0000-00-00
+Comments:
+Date: 1900-01-01
Optimiser: IRLS
[Data]
@@ -22,7 +22,7 @@ Time Parent
119 0.6
NewDataSet: FOCUS D
-Time Parent M1
+Time Parent A1
0 99.46 0
0 102.04 0
1 93.5 4.84
@@ -49,9 +49,9 @@ Time Parent M1
[Model]
ParentCompartment: Parent parent parent
-Compartment: M1 m1 m1
-Link: Parent M1 0.5 0 1 Free Explicit
+Compartment: A1 m1 m1
+Link: Parent A1 0.5 0 1 Free Explicit
[ComponentNames]
Parent:parent
-M1:m1
+A1:m1
diff --git a/tests/testthat/FOCUS_2006_D.rds b/tests/testthat/FOCUS_2006_D.rds
index ff3b4f0f..3df805c8 100644
--- a/tests/testthat/FOCUS_2006_D.rds
+++ b/tests/testthat/FOCUS_2006_D.rds
Binary files differ
diff --git a/tests/testthat/test_CAKE_export.R b/tests/testthat/test_CAKE_export.R
index b3941f1b..abedc9eb 100644
--- a/tests/testthat/test_CAKE_export.R
+++ b/tests/testthat/test_CAKE_export.R
@@ -1,13 +1,22 @@
context("Export dataset for reading into CAKE")
test_that("Exporting is reproducible", {
- CAKE_export(
+ expect_error(CAKE_export(
ds = list("FOCUS C" = FOCUS_2006_C,
"FOCUS D" = FOCUS_2006_D),
map = c(parent = "Parent", m1 = "M1"),
links = c(parent = "m1"),
filename = "FOCUS_2006_D.csf", overwrite = TRUE,
- study = "FOCUS 2006 D", date = "Dummy date 0000-00-00")
+ study = "FOCUS 2006 D", date = "1900-01-01"),
+ "elements of map have to be CAKE compartment names"
+ )
+ CAKE_export(
+ ds = list("FOCUS C" = FOCUS_2006_C,
+ "FOCUS D" = FOCUS_2006_D),
+ map = c(parent = "Parent", m1 = "A1"),
+ links = c(parent = "m1"),
+ filename = "FOCUS_2006_D.csf", overwrite = TRUE,
+ study = "FOCUS 2006 D", date = "1900-01-01")
csf <- readLines(con = "FOCUS_2006_D.csf")
expect_known_value(csf, file = "FOCUS_2006_D.rds")
expect_error(CAKE_export(ds = list("FOCUS C" = FOCUS_2006_C),

Contact - Imprint