[R] Checking for adequate disk space

bogdan romocea br44114 at gmail.com
Wed Oct 3 21:32:39 CEST 2007


Run df from R; here's an example (run on Interix):
$ df /dev/fs/C/WINDOWS
Filesystem           512-blocks      Used Available Capacity Type  Mounted on
//HarddiskVolume2      77706400  34632424  43073976    45%   ntfs  /dev/fs/C

See man df for details.


> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of Sundar Dorai-Raj
> Sent: Wednesday, October 03, 2007 2:41 PM
> To: r-help at r-project.org
> Subject: [R] Checking for adequate disk space
>
> 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)
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list