aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-01-13 14:05:31 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2015-01-13 14:36:16 +0100
commit891af5d0f1ee8d45cd4403af43293463d23ba96b (patch)
treebf4b40b47796b9973dc3d78dde20a8a8e8c2ef22 /pkg
parent4d74570f1ca4a94d894c6c5169684a8246d0a51c (diff)
README.rmd with example, fix reading unzipped files
Diffstat (limited to 'pkg')
-rw-r--r--pkg/R/TOXSWA_cwa.R11
1 files changed, 8 insertions, 3 deletions
diff --git a/pkg/R/TOXSWA_cwa.R b/pkg/R/TOXSWA_cwa.R
index 8ac6c2d..8c93183 100644
--- a/pkg/R/TOXSWA_cwa.R
+++ b/pkg/R/TOXSWA_cwa.R
@@ -152,12 +152,15 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
cwas = NULL,
windows = NULL,
events = NULL,
- initialize = function(filename, basedir, zipfile, segment = "last") {
+ initialize = function(filename, basedir, zipfile = NULL, segment = "last") {
self$filename <- filename
self$basedir <- basedir
self$zipfile <- zipfile
- if (!is.null(zipfile)) try((file_connection <- unz(zipfile, paste0(basedir, "/", filename))))
- else try((file_connection <- file(file.path(basedir, filename))))
+ if (!is.null(zipfile)) {
+ try(file_connection <- unz(zipfile, paste0(basedir, "/", filename)))
+ } else {
+ try(file_connection <- file(file.path(basedir, filename), "rt"))
+ }
cwa_all_segments <- try(read.table(file_connection,
sep = "", skip = 40,
colClasses = c("character", "numeric",
@@ -165,6 +168,8 @@ TOXSWA_cwa <- R6Class("TOXSWA_cwa",
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")) {
available_segments = 1:max(cwa_all_segments$segment)
if (segment == "last") segment = max(available_segments)

Contact - Imprint