Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge pull request #10 from HendrikSchultheis/na
Browse files Browse the repository at this point in the history
Parser performance
  • Loading branch information
HendrikSchultheis authored Apr 3, 2018
2 parents 406eee6 + 9829033 commit 7473410
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,25 @@ parser <- function(file, dec = ".") {
message(paste("Parsing file:", file))

#number of rows for each part
file.lines <- data.table::fread(file, header = FALSE, fill = TRUE, select = 1)[[1]]
num.header <- length(grep("^!", file.lines))
num.metadata <- length(grep("^#", file.lines))
con <- file(file, open = "r")
num.header <- 0
num.metadata <- 0

tryCatch(expr = {
while(TRUE) {
line <- readLines(con = con, n = 1)

if(grepl("^!", line, perl = TRUE)) {
num.header <- num.header + 1
} else if(grepl("^#", line, perl = TRUE)) {
num.metadata <- num.metadata + 1
} else {
break
}
}
}, finally = {
close(con = con)
})

###parse header
header <- data.table::fread(input = file, fill = TRUE, header = FALSE, dec = dec, nrows = num.header, integer64 = "double")
Expand Down

0 comments on commit 7473410

Please sign in to comment.