Take the 2-minute tour ×

I am using RStudio for some data analysis. System specs: i5 + 4GB RAM. For some reason, my RStudio is taking up a chunk of my RAM much much bigger than my data which leaves me with very little space for other operations. I read a 550MB csv file, memory taken by R: 1.3 - 1.5GB I saved the csv as a .RData file. File size: 183MB. Loaded the file in RStudio, memory taken by R: 780MB. Any idea why this could be happening and how to fix it?

Edits: The file has 123 columns and 1190387 rows. The variables are of type num and int.

share|improve this question
Without a reproducible example it is hard to comment on this –  Paul Hiemstra Jul 30 '12 at 4:50
It would help if you would tell us how many rows and columns you have, and what class (character, numeric, integer, factor?) each column is. Maybe add the results of str(my_data_frame) to your question. Here is a wild guess: Try adding stringsAsFactors=FALSE to your read.table() call. –  bdemarest Jul 30 '12 at 5:05
@bdemarest The file has 123 columns and 1190387 rows. The variables are of type num and int. I did add stringsAsFactors = FALSE to my read.csv() call but it didn't make a difference in the memory usage. –  Macbook Jul 30 '12 at 16:19
add comment

2 Answers


In addition, it is not evident a 550 mb csv file maps to 550 mb in R. This depends on the data types of the columns (float, int, character),which all use different amounts of memory.

The fact that your Rdata file is smaller is not strange as R compresses the data, see the documentation of save.

share|improve this answer
I guess the only way I can save memory is by storing the data in a SQLite database and calling only a few a columns at a time. gc didn't really help. This is what I got when I used the function - function (verbose = getOption("verbose"), reset = FALSE) { res <- .Internal(gc(verbose, reset)) res <- matrix(res, 2L, 7L, dimnames = list(c("Ncells", "Vcells"), c("used", "(Mb)", "gc trigger", "(Mb)", "limit (Mb)", "max used", "(Mb)"))) if (all(is.na(res[, 5L]))) res[, -5L] else res } <bytecode: 0x05ab2fb8> <environment: namespace:base> –  Macbook Aug 1 '12 at 10:27
Try using gc(), not gc. Typing a function without the parentheses leads to R showing the R source code of a function. –  Paul Hiemstra Aug 1 '12 at 11:26
add comment

A numeric value (double precision floating point) is stored in 8 bytes of ram.
An integer value (in this case) uses 4 bytes.
Your data has 1,190,387 * 123 = 146,417,601 values.
If all columns are numeric that makes 1,171,340,808 bytes of ram used (~1.09GB).
If all are integer then 585,670,404 bytes are needed (~558MB).

So it makes perfect sense that your data uses 780MB of ram.

Very General Advice:

  1. Convert your data.frame to a matrix. Matrix operations often have less overhead.
  2. Try R package bigmemory: http://cran.r-project.org/web/packages/bigmemory/index.html
  3. Buy more ram. Possibly your machine can support up to 16GB.
  4. Don't load all your data into ram at the same time. Load subsets of rows or columns, analyze, save results, repeat.
  5. Use a very small test dataset to design your analysis, then analyze the full dataset on another machine/server with more memory.
share|improve this answer
I've also found that if you read/reduce files in a shell (I use Cygwin) then send to R, memory becomes less of an issue. –  RScriv Feb 25 at 19:38
add comment

Your Answer


