Commit a55eca6f authored by Enrico Schumann's avatar Enrico Schumann

Version 0.4-8

write_ts_table: simplify code for add/overwrite;
update docs
parent e88a1640
2017-05-26 Enrico Schumann <es@enricoschumann.net>
* DESCRIPTION (Version): 0.4-8
* R/functions.R (write_ts_table): simplify code
for add/overwrite
* man/write_ts_table.Rd: update docs
2017-05-22 Enrico Schumann <es@enricoschumann.net>
* DESCRIPTION (Version): 0.4-7
......
Package: tsdb
Type: Package
Title: Terribly-Simple Data Base for Time Series
Version: 0.4-7
Date: 2017-05-22
Version: 0.4-8
Date: 2017-05-26
Maintainer: Enrico Schumann <es@enricoschumann.net>
Authors@R: person("Enrico", "Schumann",
role = c("aut", "cre"),
......
......@@ -97,7 +97,7 @@ write_ts_table <- function(x, dir, file,
if (any(in_db$columns != columns))
stop("columns in file differ from columns in ", sQuote("x"))
new <- !timestamp %in% ttime(in_db$timestamp)
ans <- 0
ans <- 0L
if (any(new)) {
ans <- sum(new)
timestamp <- c(ttime(in_db$timestamp),
......@@ -115,9 +115,11 @@ write_ts_table <- function(x, dir, file,
message("file exists; use ", sQuote("add = TRUE"),
" or ", sQuote("overwrite = TRUE"),
" to update file")
} else if (add && sum(new) == 0L) {
ans <- 0
} else {
} else if (ans > 0L) {
## only write if there are rows (ans > 0):
## e.g., if 'add' was true but no new data were
## found, there is no need to rewrite the table
write.table(as.matrix(data.frame(timestamp, unclass(x))),
file = dfile,
row.names = FALSE,
......
......@@ -91,9 +91,9 @@ test.read_ts_tables <- function() {
test.write_ts_table <- function() {
require("RUnit")
require("tsdb")
require("zoo")
## require("RUnit")
## require("tsdb")
## require("zoo")
dir <- tempdir()
x <- ts_table(data = 11:15,
......@@ -244,7 +244,7 @@ test.write_ts_table <- function() {
checkEquals(ans, 1)
checkEquals(readLines(file.path(dir, "x")),
c("\"timestamp\",\"X\"",
"16436,2", ## value remains unchanged
"16436,2", ## value is changed because of 'overwrite'
"16802,11",
"16803,12",
"16804,13",
......
\name{file_info}
\alias{file_info}
\title{
Information about Data File
}
\description{
Provides information about data stored in file:
columns, number of observations, range of timestamps.
}
\usage{
file_info(dir, file)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{dir}{
character
}
\item{file}{
character
}
}
\details{
Experimental.
}
\value{
An object of type \code{file_info}, which is a
\code{data.frame}.
}
\author{
Enrico Schumann
}
\seealso{
\code{\link{ts_table}}
}
\examples{
\dontrun{
file_info(dir = "/tsdb",
c("table1", "table2"))}
}
......@@ -41,10 +41,30 @@ write_ts_table(x, dir, file, add = FALSE, overwrite = FALSE, backend = "csv")
}
\details{
Write files.
The function takes a \code{ts_table} and writes it to
a file.
If the file already exist and both \code{add} and
\code{overwrite} are \code{FALSE} (the default),
nothing is written.
When \code{add} is \code{TRUE}, the function checks
if \code{x} contains timestamps not yet in the file
and, if there are any, writes only those data.
When \code{overwrite} is \code{TRUE}, the function
merges all observations in the file with those in
\code{x} and writes the result back to the file. If
\code{x} contains timestamps that were already in the
file, the data in the file are overwritten. Note that
no data will be removed from the file: timestamps not
in \code{x} remain unchanged in the file.
}
\value{
The number of data rows written to a file.
Invisibly, the number of data rows written to a file.
}
\author{
Enrico Schumann
......
message(getwd())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment