Commit 04a97b35 authored by Enrico Schumann's avatar Enrico Schumann

[write_ts_table] New argument 'replace.file'

Default is FALSE. If TRUE, the specified file is
*deleted* and then replaced by the new ts-table.
parent 70f6e599
2017-11-16 Enrico Schumann <es@enricoschumann.net>
* R/functions.R (write_ts_table): new argument
'replace.file', with default FALSE. If TRUE,
the specified file is *deleted* and then
replaced by the new ts_table
2017-11-14 Enrico Schumann <es@enricoschumann.net>
* R/functions.R (file_info): simplify code;
......
......@@ -54,7 +54,9 @@ ttime <- function(x, from = "datetime", to = "numeric",
write_ts_table <- function(ts, dir, file,
add = FALSE, overwrite = FALSE,
add = FALSE,
overwrite = FALSE,
replace.file = FALSE,
backend = "csv") {
if (!(inherits(ts, "ts_table")))
stop(sQuote("ts"), " must be a ", sQuote("ts_table"))
......@@ -71,6 +73,9 @@ write_ts_table <- function(ts, dir, file,
file
else
file.path(dir, file)
if (replace.file) {
file.remove(dfile)
}
if (ans == 0L) {
if (!file.exists(dfile))
write.table(as.matrix(data.frame(timestamp, unclass(ts))),
......@@ -451,4 +456,9 @@ print.ts_table <- function(x, ...) {
adjust_ts_table <- function(ts, dividends, splits, splits.first = TRUE) {
}
rm_ts_table <- function(file, dir, ..., trash.bin = ".trash.bin") {
}
......@@ -13,7 +13,7 @@
}
\usage{
ttime(x, from = "datetime", to = "numeric", tz = "",
strip.attr = FALSE, format = "\%Y-\%m-\%d")
strip.attr = TRUE, format = "\%Y-\%m-\%d")
}
\arguments{
\item{x}{
......@@ -29,7 +29,7 @@ ttime(x, from = "datetime", to = "numeric", tz = "",
character
}
\item{strip.attr}{
logical
logical: strip attributes; in particular, timezone information
}
\item{format}{
character
......
......@@ -7,7 +7,8 @@
Write time-series data to files.
}
\usage{
write_ts_table(ts, dir, file, add = FALSE, overwrite = FALSE, backend = "csv")
write_ts_table(ts, dir, file, add = FALSE, overwrite = FALSE,
replace.file = FALSE, backend = "csv")
}
\arguments{
......@@ -31,6 +32,12 @@ write_ts_table(ts, dir, file, add = FALSE, overwrite = FALSE, backend = "csv")
logical: overwrite existing file when data
differs. \code{overwrite} implies \code{add}.
}
\item{replace.file}{
logical: if \code{TRUE}, an existing file is deleted
and replaced by a new file (i.e. containing \code{ts}))
}
\item{backend}{
......
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