aboutsummaryrefslogtreecommitdiff
path: root/pkg/R/TOXSWA_cwa.R
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/R/TOXSWA_cwa.R
parent057ba40426d49e09c06db26fb7d4072741b4cb8d (diff)
Improve reading spead for new TOXSWA format
Diffstat (limited to 'pkg/R/TOXSWA_cwa.R')
-rw-r--r--pkg/R/TOXSWA_cwa.R26
1 files changed, 15 insertions, 11 deletions
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) {

Contact - Imprint