[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to speed up reading data from a txt file in R?

Posted on 2014-11-30
13
Medium Priority
?
289 Views
Last Modified: 2014-12-10
Hi,

I have a very large file (800 MB) to be read in R from a txt files and it takes several minutes to do so. I need it to be much quicker.

 Is there any functions, packages, or tricks to read in data much quicker than what I am doing?

I have included my code and the dataset.
I use a HP laptop with intel i7 and windows8.

Thank you for you help.


### time the first way
start.time.data1<-Sys.time()

data1<-read.table("XYZ_EE.txt",sep=",",stringsAsFactor=F,header=F)

time.data1<-Sys.time()-start.time.data1
time.data1  ## Time difference of 1.523134 secs


### time the second way
start.time.data2<-Sys.time()

data2<-read.table("XYZ_EE.txt",sep=",",stringsAsFactor=F,header=F,
                  colClasses=c("character","character","numeric","numeric"))

time.data2<-Sys.time()-start.time.data2
time.data2  ## Time difference of 1.497055 secs

Open in new window

XYZ-EE.txt
0
Comment
Question by:pgmerLA
13 Comments
 
LVL 43

Assisted Solution

by:pcelba
pcelba earned 440 total points
ID: 40473446
Notepad reads your file 8 secs independently on the drive type used. And Notepad is very bad at this field... MS Excel is faster. The R speed is derived by the R itself.

It seems the only way is parallelism in your task...

I suppose you don't need all detail data in one program instance. Simply split your file into several parts and execute these parts separately. This will be limited by your disk speed so I would recommend to use SSD drive.

If you need to process all data at once (and no way to speed the R up exists) then you should look for faster processing in e.g. C++. Or you may use C++ to preprocess/reduce your data.

For more advanced R solution you may look here: http://cran.r-project.org/web/views/HighPerformanceComputing.html
http://dirk.eddelbuettel.com/papers/useR2009hpcTutorial.pdf
0
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 100 total points
ID: 40473472
Do you have 800MB+ free RAM (physical memory) when you begin reading?

The reason I used the plus sign is that R will need additional memory to do statistics.
0
 
LVL 16

Assisted Solution

by:dhsindy Sparrow
dhsindy Sparrow earned 260 total points
ID: 40473625
Are you using a 32 or 64 bit system?  I am assuming a 64-bit since i7 processor.  Disk speed and memory comes to mind.  Verify the file is loaded all to the memory and not virtually to the disk.  Do you have ample free space (30%) on your hard disk.

Also, you didn't mention where the file is stored, hard disk, cloud, etc.  Other things to look for  are other processes that might be taking priority - like a security program, or other - I use Malwarebytes and I noticed it periodically kicks in and uses up to 30% of my RAM. I frequently stop my security program when loading large files and then restart it after the file is loaded.

I would start "Task Manager"/or other process manager and watch the memory processes as it loads, maybe increase the priority of that process.  And, look for other processes hogging resources.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 36

Accepted Solution

by:
Gary Patterson earned 1200 total points
ID: 40473679
How about fread() instead of read.table()?

http://davetang.org/muse/2013/09/03/handling-big-data-in-r/

Here's a nice comparison of some basic techniques to load big data into memory:

http://yanran.li/2013/10/loading-big-data-in-R/
0
 

Author Comment

by:pgmerLA
ID: 40492825
Thank you all for your answers.

I have used GaryPatterson advice on fread() and I was able to reduce the time considerably

> system.time(data1<-fread("XYZ_EE.txt",sep=",",header=F))
   user  system elapsed 
   0.59    0.00    0.61 
> system.time(data2<-read.table("XYZ_EE.txt",sep=",",header=F))
   user  system elapsed 
   1.64    0.03    1.67 

Open in new window

0
 

Author Comment

by:pgmerLA
ID: 40492829
The system I use:

i7 4700MQ @2.4 Ghz
16 GB RAM DDR3
64bit Windows8
1TB hard drive
0
 
LVL 43

Expert Comment

by:pcelba
ID: 40492834
At least some speeding is good.
0
 

Author Comment

by:pgmerLA
ID: 40492843
Hi pcelba,

How can I follow your advice in R?  "I would recommend to use SSD drive"
0
 
LVL 43

Expert Comment

by:pcelba
ID: 40492852
It was just a brainstorming... or hardware solution.

Any HDD swap for SSD drive will speed your computer up. I am using notebooks with SSD C: drive and it is much faster than any older desktop.

The notebook uses just i7-3610QM but its experience index is 7.
0
 

Author Comment

by:pgmerLA
ID: 40492873
Are you using an external SSD C:drive?

How much faster do you think my program will get?

What do you mean by "The notebook uses just i7-3610QM but its experience index is 7"?
0
 
LVL 43

Expert Comment

by:pcelba
ID: 40492883
My SSD is internal. External would need USB 3 connection and it also does not speed the OS up.

Sorry I cannot predict the speed improvement.

 i7-3610QM is slower than 4700MQ: http://ark.intel.com/compare/75117,64899
but thanks to SSD the notebook speed index is 7.
0
 

Author Comment

by:pgmerLA
ID: 40492910
Thank you pcelba. I will keep that really good advise in mind!
0
 
LVL 43

Expert Comment

by:pcelba
ID: 40492920
You are welcome.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question