aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorJohannes Ranke <johannes.ranke@jrwb.de>2016-02-04 17:45:02 +0100
committerJohannes Ranke <johannes.ranke@jrwb.de>2016-02-04 17:45:02 +0100
commit98a706373107188496a1df295697e739e51d6b06 (patch)
tree84503adba976775559eea20e5c20c9ea5b9c42cd /pkg
parent057ba40426d49e09c06db26fb7d4072741b4cb8d (diff)
Improve reading spead for new TOXSWA format
Diffstat (limited to 'pkg')
-rw-r--r--pkg/DESCRIPTION3
-rw-r--r--pkg/NAMESPACE2
-rw-r--r--pkg/R/TOXSWA_cwa.R26
-rw-r--r--pkg/inst/testdata/SwashProjects.zipbin5032617 -> 7989179 bytes
-rw-r--r--pkg/man/PEC_sw_drift.Rd2
-rw-r--r--pkg/man/PEC_sw_sed.Rd2
-rw-r--r--pkg/man/read.TOXSWA_cwa.Rd9
7 files changed, 28 insertions, 16 deletions
diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION
index 1cc6817..ab3e92a 100644
--- a/pkg/DESCRIPTION
+++ b/pkg/DESCRIPTION
@@ -13,7 +13,8 @@ Depends:
mkin
Imports:
graphics,
- chents
+ chents,
+ readr
Suggests:
testthat
License: GPL
diff --git a/pkg/NAMESPACE b/pkg/NAMESPACE
index 0632e51..c59559b 100644
--- a/pkg/NAMESPACE
+++ b/pkg/NAMESPACE
@@ -24,3 +24,5 @@ import(chents)
import(graphics)
import(mkin)
importFrom(R6,R6Class)
+importFrom(readr,fwf_empty)
+importFrom(readr,read_fwf)
diff --git a/pkg/R/TOXSWA_cwa.R b/pkg/R/TOXSWA_cwa.R
index 46b1995..a693dc1 100644
--- a/pkg/R/TOXSWA_cwa.R
+++ b/pkg/R/TOXSWA_cwa.R
@@ -34,6 +34,7 @@
#' maximum time weighted average concentrations and areas under the curve.
#' @param thresholds Numeric vector of threshold concentrations in µg/L for
#' generating event statistics.
+#' @importFrom readr read_fwf fwf_empty
#' @return An instance of an R6 object of class
#' \code{\link{TOXSWA_cwa}}.
#' @export
@@ -174,17 +175,18 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
} else {
try(file_connection <- file(file.path(basedir, filename), "rt"))
}
+
if (grepl(".cwa$", filename)) {
# cwa file from FOCUS TOXSWA 3 (TOXSWA 2.x.y)
- cwa_all_segments <- try(read.table(file_connection,
- sep = "", skip = 40,
- encoding = "UTF-8",
- colClasses = c("character", "numeric",
- "integer", rep("numeric", 5)),
- col.names = c("datetime", "t", "segment",
- "xcd", "cwa_tot", "cwa",
- "Xss", "Xmp")))
+ cwa_all_segments <- try(
+ read.table(file_connection,
+ sep = "", skip = 40,
+ encoding = "UTF-8",
+ colClasses = c("character", "numeric",
+ "integer", rep("numeric", 5)),
+ col.names = c("datetime", "t", "segment",
+ "xcd", "cwa_tot", "cwa", "Xss", "Xmp")))
if (is.null(zipfile)) close(file_connection) # only needed for files
if (!inherits(cwa_all_segments, "try-error")) {
@@ -225,15 +227,17 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
stop("Could not read ", filename)
} else {
cwa_lines <- outfile[grep("ConLiqWatLay_", outfile)] # hourly concentrations
- cwa_all_segments <- read.table(text = cwa_lines)
+
+ cwa_all_segments <- read_fwf(paste(cwa_lines, collapse = "\n"),
+ fwf_empty(paste(tail(cwa_lines), collapse = "\n")))
available_segments = 1:(ncol(cwa_all_segments) - 3)
if (segment == "last") segment = max(available_segments)
if (!segment %in% available_segments) stop("Invalid segment specified")
self$segment <- segment
cwa <- data.frame(
- datetime = as.character(cwa_all_segments$V2),
- t = cwa_all_segments$V1,
+ datetime = as.character(cwa_all_segments$X2),
+ t = cwa_all_segments$X1,
cwa = cwa_all_segments[[3 + segment]]
)
if (total) {
diff --git a/pkg/inst/testdata/SwashProjects.zip b/pkg/inst/testdata/SwashProjects.zip
index 49507c9..5b9ff49 100644
--- a/pkg/inst/testdata/SwashProjects.zip
+++ b/pkg/inst/testdata/SwashProjects.zip
Binary files differ
diff --git a/pkg/man/PEC_sw_drift.Rd b/pkg/man/PEC_sw_drift.Rd
index c486831..6a1b935 100644
--- a/pkg/man/PEC_sw_drift.Rd
+++ b/pkg/man/PEC_sw_drift.Rd
@@ -6,7 +6,7 @@
\usage{
PEC_sw_drift(rate, applications = 1, water_depth = 30, drift_data = "JKI",
crop = "Ackerbau", distances = c(1, 5, 10, 20), rate_units = "g/ha",
- PEC_units = "µg/L")
+ PEC_units = "<U+00B5>g/L")
}
\arguments{
\item{rate}{Application rate in units specified below}
diff --git a/pkg/man/PEC_sw_sed.Rd b/pkg/man/PEC_sw_sed.Rd
index 3140eb0..d0e2ec6 100644
--- a/pkg/man/PEC_sw_sed.Rd
+++ b/pkg/man/PEC_sw_sed.Rd
@@ -7,7 +7,7 @@ water concentrations}
\usage{
PEC_sw_sed(PEC_sw, percentage = 100, method = "percentage",
sediment_depth = 5, water_depth = 30, sediment_density = 1.3,
- PEC_sed_units = c("µg/kg", "mg/kg"))
+ PEC_sed_units = c("<U+00B5>g/kg", "mg/kg"))
}
\arguments{
\item{PEC_sw}{Numeric vector or matrix of surface water concentrations in µg/L for
diff --git a/pkg/man/read.TOXSWA_cwa.Rd b/pkg/man/read.TOXSWA_cwa.Rd
index acc384c..44a7542 100644
--- a/pkg/man/read.TOXSWA_cwa.Rd
+++ b/pkg/man/read.TOXSWA_cwa.Rd
@@ -5,10 +5,11 @@
\title{Read TOXSWA surface water concentrations}
\usage{
read.TOXSWA_cwa(filename, basedir = ".", zipfile = NULL, segment = "last",
- windows = NULL, thresholds = NULL)
+ total = FALSE, windows = NULL, thresholds = NULL)
}
\arguments{
-\item{filename}{The filename of the cwa file.}
+\item{filename}{The filename of the cwa file (TOXSWA 2.x.y or similar) or the
+out file (FOCUS TOXSWA 4, i.e. TOXSWA 4.4.2 or similar).}
\item{basedir}{The path to the directory where the cwa file resides.}
@@ -17,6 +18,10 @@ read.TOXSWA_cwa(filename, basedir = ".", zipfile = NULL, segment = "last",
\item{segment}{The segment for which the data should be read. Either "last", or
the segment number.}
+\item{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.}
+
\item{windows}{Numeric vector of width of moving windows in days, for calculating
maximum time weighted average concentrations and areas under the curve.}

Contact - Imprint