-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed attempts at speeding up reading (i.e. things which are not faster than fread). #13
Labels
Comments
Chris1221
changed the title
Things which are slower than fread
Failed attempts at speeding up reading (i.e. things which are not faster than fread).
May 18, 2016
Reading in as a for(k in 1:5){
if(k == 1){
f = file(paste0(path, "chr1_block_", i, "_perm_", j, "_k_", k, ".controls.gen"), h = F, sep = " "))
sqldf("select * from f", dbname = tempfile(), file.format = list(header = T, row.names = F)) -> gen
} else if(k != 1){
f = file(paste0(path, "chr1_block_", i, "_perm_", j, "_k_", k, ".controls.gen"), h = F, sep = " "))
sqldf("select * from f", dbname = tempfile(), file.format = list(header = T, row.names = F)) %>% data.table::merge(gen, ., by = "V1:V5") %>% cbind(gen, .) -> gen
}
} |
Read lines was at least 100 times slower. inputFile <- "../inst/extdata/toy.gen"
system.time({
con <- file(inputFile, open = "r")
out <- data.table(ID = 1:1000)
while (length(oneLine <- readLines(con, n = 1, warn = FALSE)) > 0) {
myVector <- (strsplit(oneLine, " "))
myVector <- as.vector(as.factor(unlist(myVector)))
foreach(row = 1:nrow(gen)) %:% foreach(i = seq(6,((length(myVector)-2)),by=3), .combine = c) %do% {
myVector <- gen[row,]
j <- i + 1
h <- i + 2
one <- myVector[i]
two <- myVector[j]
three <- myVector[h]
final <- NA
if (one > 0.9) {
final <- 0
} else if (two > 0.9) {
final <- 1
} else if (three > 0.9) {
final <- 2
} else {
final <- NA
}
final
}
out[, myVector[3] := vec, with = FALSE] -> out
message(paste0(ncol(out)))
} |
The above was also slower when library(doParallel)
makeCluster(8) Then |
Reading lines one at a time with |
Chaining rows together with |
|
Issue #19 might do it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Attempts at speeding up the reading and converting of
.gen
files.This thread exists as a warning and reminder to myself of how truly awful I am at programming.
The text was updated successfully, but these errors were encountered: