Commit 05667546 authored by Enrico Schumann's avatar Enrico Schumann

[read_ts_tables] Use data.table::fread

Experimental new argument 'fread'. When TRUE, files are
read with data.table::fread instead of read.table.
parent a219a4c8
2018-02-01 Enrico Schumann <es@enricoschumann.net>
* R/functions.R (read_ts_tables): experimental
new argument 'fread'; if TRUE, files are read
with data.table::fread instead of read.table
2017-12-11 Enrico Schumann <es@enricoschumann.net>
* NAMESPACE: export 'ttime'
......@@ -16,7 +22,7 @@
2017-10-24 Enrico Schumann <es@enricoschumann.net>
* DESCRIPTION (Version): Version: 0.5-0
* DESCRIPTION (Version): 0.5-0
* R/functions.R (ts_table): store timestamp as
numeric (which reverts the change introduced in
......
......@@ -13,4 +13,4 @@ Description: A terribly-simple data base for time series. All
joining data.
License: GPL-3
Imports: DBI, datetimeutils, fastmatch, utils, zoo
Suggests: MonetDBLite
Suggests: MonetDBLite, data.table
## The package uses code from Enrico Schumann's
## R package 'database'.
## Copyright Enrico Schumann 2010-2017
## Copyright (C) Enrico Schumann 2010-2018
## ---------------- time
......@@ -153,7 +153,8 @@ read_ts_tables <- function(file, dir, t.type = "guess",
return.class = NULL,
drop.weekends = TRUE,
column.names = "%dir%/%file%::%column%",
backend = "csv") {
backend = "csv",
fread = FALSE) {
backend <- tolower(backend)
......@@ -230,9 +231,17 @@ read_ts_tables <- function(file, dir, t.type = "guess",
results <- array(NA_real_,
dim = c(length(timestamp), length(dfile)*nc))
for (i in seq_along(dfile)) {
tmp <- read.table(dfile[[i]], sep = ",",
stringsAsFactors = FALSE,
header = TRUE, colClasses = "numeric")
if (fread)
tmp <- data.table::fread(dfile[[i]],
sep = ",",
header = TRUE,
data.table = FALSE)
else
tmp <- read.table(dfile[[i]],
sep = ",",
stringsAsFactors = FALSE,
header = TRUE,
colClasses = "numeric")
ii <- fmatch(tmp[[1L]], timestamp, nomatch = 0L)
tmp.names <- colnames(tmp)
if (!all(columns %in% tmp.names)) {
......@@ -291,11 +300,6 @@ read_ts_tables <- function(file, dir, t.type = "guess",
}
}
## x <- scan("~/tsdb/daily/cmcier", what= list(numeric(0), numeric(0)),
## skip = 1, sep = ",", multi.line=FALSE)
## read.table("~/tsdb/daily/cmcier", colClasses = "numeric", header = TRUE)
dir_info <- function(dir = getwd()) {
res <- dir()
class(res) <- "dir_info"
......@@ -305,7 +309,6 @@ print.dir_info <- function(x, ...) {
print(unclass(x))
}
file_info <- function(dir, file) {
dfile <- if (missing(dir))
file
......
......@@ -12,7 +12,8 @@ read_ts_tables(file, dir, t.type = "guess",
return.class = NULL,
drop.weekends = TRUE,
column.names = "\%dir\%/\%file\%::\%column\%",
backend = "csv")
backend = "csv",
fread = FALSE)
}
\arguments{
\item{file}{
......@@ -48,6 +49,10 @@ read_ts_tables(file, dir, t.type = "guess",
\item{backend}{
character: currently, \code{csv} and \code{monetdb} are supported
}
\item{fread}{
logical: use \code{\link[data.table]{fread}}
from package \pkg{data.table}?
}
}
\details{
......@@ -69,7 +74,7 @@ read_ts_tables(file, dir, t.type = "guess",
}
\examples{
\dontrun{
read_ts_tables(c("table1", "table2"), dir = "/tsdb",
read_ts_tables(c("table1", "table2"), dir = "~/tsdb",
columns = "close",
return.class = "zoo")}
}
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