Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Read CSV records from a file written by serlog.py
#' read.serlog
#'
#' Read CSV records from a file written by serlog.py
#'
#' @param file filename
#' @param varnames column names for the resulting \link{zoo} object
#' @export
read.serlog <- function(file, varnames) {
require(zoo)
options(digits.secs=3)
content <- gsub("\\t", ",", readLines(file))
columns <- c('datetime', 'millis', 'logger', 'loglevel', varnames)
records <- read.csv(textConnection(content), header=FALSE, stringsAsFactors=FALSE, col.names=columns)
timestamps <- with(records, paste(datetime, millis, sep='.'))
times <- as.POSIXct(strptime(timestamps, "%Y-%m-%d %H:%M:%OS"))
zoo(records[,5:ncol(records)], order.by=times)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment