[R] Checking for adequate disk space

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Wed Oct 3 20:40:38 CEST 2007


Hi, all,

(version info at end)

I'm running a script which takes input files, does some analysis, and 
writes the output to csv files. Last night I ran the script (it took 
~6.5 hours) thinking all would go well since it ran on a subset of the 
data without issue. However, when I returned this morning more than half 
the output files had no data. I checked the Rout file for errors and 
there were none. After spending about an hour debugging the script I 
learned the problem was not the script, but I ran out of disk space. But 
write.table, along with the rest of the script, still continued as if 
nothing was wrong.

My question is: How can I programmatically determine if a user has 
adequate space to use write.* and then throw an error if they don't? I'm 
running R on Linux (RHEL4). For the short term, I will accept Linux-only 
solutions but would prefer an OS-free solution.

My quick-and-dirty solution is to use:

write.csv(x, file)
if(file.info(file)["size"] == 0)
   stop("you *may* have run out of disk space")

However, this solution may not work as there may be other reasons the 
file size is 0 (e.g. x is NULL or 0-length?).

 > x <- character(0)
 > write.table(x, "file", col.names = FALSE, row.names = FALSE)
 > file.info("file")["size"]
      size
file    0
 >
 > version
                _
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status
major          2
minor          5.1
year           2007
month          06
day            27
svn rev        42083
language       R
version.string R version 2.5.1 (2007-06-27)



More information about the R-help mailing list