Specifying a colClasses argument to read.table or read.csv can save time on importing data, while also saving steps to specify classes for each variable later.
For example, loading a 893 MB took 441 seconds to load when not using colClasses, but only 268 seconds to load when using colClasses. The system.time function in base can help you check your own times.
Without specifying colClasses:
When specifying colClasses:
The classes you can specify are: factor, character, integer, numeric, logical, complex, and Date. Dates that are in the form %Y-%m-%d or Y/%m/%d will import correctly. This tip allows you to import dates properly for dates in other formats.
If there aren’t any classes that you want to change from their defaults, you can read in the first few rows, determine the classes from that, and then import the rest of the file:
If you aren’t concerned about the time it takes to read the data file, but instead just want the classes to be correct on import, you have the option of only specifying certain classes:
Citations and Further Reading
This post is one part of my series on dealing with large datasets.