To check to see if an object with that name is already loaded, we can use the exists function from the base package. We can then wrap our read.csv command with an if statement to cause the file to only load if an object with that name is not already loaded.
if(!exists("largeData")) { largeData <- read.csv("huge-file.csv", header = TRUE) }
You will probably also find it useful to use the "colClasses" option of read.csv or read.table to help the file load faster and make sure your data are in the right format. For example:
if(!exists("largeData")) { largeData <- read.csv("huge-file.csv", header = TRUE, colClasses = c("factor", "integer", "character", "integer", "integer", "character")) }
--
This post is one part of my series on dealing with large datasets.