Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created June 22, 2012 18:39
Show Gist options
  • Save dholstius/2974446 to your computer and use it in GitHub Desktop.
Save dholstius/2974446 to your computer and use it in GitHub Desktop.
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