Last active
August 29, 2015 13:56
-
-
Save al2na/8958698 to your computer and use it in GitHub Desktop.
read.table faster with known column classes and data.table::fread. I wonder which one is
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.readTableFast<-function(filename,header=T,skip=0,sep="") | |
{ | |
tab5rows <- read.table(filename, header = header,skip=skip,sep=sep, | |
nrows = 100,stringsAsFactors=FALSE) | |
classes <- sapply(tab5rows, class) | |
classes[classes=="logical"]="character" | |
return( read.table(filename, header = header,skip=skip,sep=sep, | |
colClasses = classes) ) | |
} | |
require(data.table) | |
.readTableFast2<-function(filename,header=T,skip=0,sep="") | |
{ | |
# probably no need for these lines as they don't seem to | |
# improve fread performance | |
tab5rows <- read.table(filename, header = header,skip=skip,sep=sep, | |
nrows = 100,stringsAsFactors=FALSE) | |
classes <- sapply(tab5rows, class) | |
classes[classes=="logical"]="character" | |
return( fread(filename, header = header,skip=skip,sep=sep, | |
colClasses = classes) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment