aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/DESCRIPTION4
-rw-r--r--pkg/R/TOXSWA_cwa.R32
2 files changed, 29 insertions, 7 deletions
diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION
index e24d04f..e3f29cc 100644
--- a/pkg/DESCRIPTION
+++ b/pkg/DESCRIPTION
@@ -1,8 +1,8 @@
Package: pfm
Type: Package
Title: Utilities for Pesticide Fate Modelling
-Version: 0.3-6
-Date: 2016-07-15
+Version: 0.3-7
+Date: 2016-07-30
Authors@R: person("Johannes Ranke", email = "jranke@uni-bremen.de",
role = c("aut", "cre", "cph"))
Description: Utilities for simple calculations of predicted environmental
diff --git a/pkg/R/TOXSWA_cwa.R b/pkg/R/TOXSWA_cwa.R
index fd056b2..c5ddce9 100644
--- a/pkg/R/TOXSWA_cwa.R
+++ b/pkg/R/TOXSWA_cwa.R
@@ -19,7 +19,7 @@
#'
#' Read TOXSWA hourly concentrations of a chemical substance in a specific
#' segment of a TOXSWA surface water body. Per default, the data for the last
-#' segment are imported. As TOXSWA reports the values at the end of the hour
+#' segment are imported. As TOXSWA 4 reports the values at the end of the hour
#' (ConLiqWatLayCur) in its summary file, we use this value as well instead
#' of the hourly averages (ConLiqWatLay).
#'
@@ -32,6 +32,9 @@
#' @param total Set this to TRUE in order to read total concentrations as well. This is
#' only necessary for .out files as generated by TOXSWA 4.4.2 or similar, not for .cwa
#' files. For .cwa files, the total concentration is always read as well.
+#' @param substance For TOXSWA 4 .out files, the default value "parent" leads
+#' to reading concentrations of the parent compound. Alternatively, the substance
+#' of interested can be selected by its code name.
#' @param windows Numeric vector of width of moving windows in days, for calculating
#' maximum time weighted average concentrations and areas under the curve.
#' @param thresholds Numeric vector of threshold concentrations in µg/L for
@@ -47,11 +50,13 @@
#' zipfile = system.file("testdata/SwashProjects.zip",
#' package = "pfm"))
read.TOXSWA_cwa <- function(filename, basedir = ".", zipfile = NULL,
- segment = "last", total = FALSE,
+ segment = "last", substance = "parent",
+ total = FALSE,
windows = NULL, thresholds = NULL)
{
if (!missing(filename)) {
- cwa <- TOXSWA_cwa$new(filename, basedir, zipfile, total = total)
+ cwa <- TOXSWA_cwa$new(filename, basedir, zipfile,
+ substance = substance, total = total)
if (!is.null(windows[1])) cwa$moving_windows(windows)
if (!is.null(thresholds[1])) cwa$get_events(thresholds)
invisible(cwa)
@@ -165,10 +170,12 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
basedir = NULL,
zipfile = NULL,
segment = NULL,
+ substance = NULL,
cwas = NULL,
windows = NULL,
events = list(),
- initialize = function(filename, basedir, zipfile = NULL, segment = "last", total = FALSE) {
+ initialize = function(filename, basedir, zipfile = NULL,
+ segment = "last", substance = "parent", total = FALSE) {
self$filename <- filename
self$basedir <- basedir
self$zipfile <- zipfile
@@ -227,7 +234,22 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
if (inherits(outfile, "try-error")) {
stop("Could not read ", filename)
} else {
- cwa_lines <- outfile[grep("ConLiqWatLayCur_", outfile)] # concentrations at end of hour
+ # Get the substance name(s)
+ sub_lines <- grep(".*0.000.*ConLiqWatLayCur_", outfile[1:50], value = TRUE)
+ substances <- gsub(".*ConLiqWatLayCur_(.*?) *[0-9].*", "\\1", sub_lines)
+ if (!substance %in% c("parent", substances)) {
+ stop("No data for substance ", substance, " present in the .out file.")
+ }
+
+ # Generate field name for the concentrations at end of hour for the
+ # substance of interest
+ if (substance == "parent") {
+ cwa_string = paste0("ConLiqWatLayCur_", substances[1])
+ } else {
+ cwa_string = paste0("ConLiqWatLayCur_", substance)
+ }
+
+ cwa_lines <- grep(cwa_string, outfile, value = TRUE)
cwa_all_segments <- read_fwf(paste(cwa_lines, collapse = "\n"),
fwf_empty(paste(tail(cwa_lines), collapse = "\n")))

Contact - Imprint