SCM

[#1952] load data from disk when overwrite=FALSE and file exists?

Date:
2012-04-19 15:03
Priority:
3
State:
Open
Submitted by:
Neil Best (nbest)
Assigned to:
Nobody (None)
Product:
None
Operating System:
All
Component:
None
Summary:
load data from disk when overwrite=FALSE and file exists?

Detailed description
Have you ever considered adding a feature such that functions recognize that if overwrite=FALSE and the data they were about to attempt to write already exists then the function should short-circuit to returning the object as if the operation had been performed?

I often find myself doing iterative development where I want to reinstantiate all of the preceding objects in a new R session without actually performing all of the calculations. Sure, saving an image would address this, but it doesn't always happen in time. I often find myself using constructs like this:

overwriteRasters <- FALSE # global "option"

someRasterObj <-
if( overwriteRasters) {
someRasterFunction(
inputRaster,
filename= "foo.tif",
overwrite= TRUE)
} else {
raster( "foo.tif")
}

This is a completely contrived example, obviously, but I think it conveys what I am trying to describe. WIth some effort it probably could be abstracted as a wrapper but some logic to decide when brick() might be needed instead of raster(), or maybe an extra arg, but it seems like it could be hidden away altogether. What do you think?

Comments:

Message  ↓
Date: 2012-04-25 23:28
Sender: Robert Hijmans

Hi Neil,
Thanks for the Interesting suggestion. I could imagine having this behavior with "overwrite=NA" but it would require changing lots of code (every function that can create a file). I am not yet convinced that it is worth it as you can do:

if (!file.exists("foo.tif")) { someRasterFun(input, filename='foo.tif') }

A bit more verbose, but it would be very clear what is going on.

Attached Files:

Changes

No Changes Have Been Made to This Item

Thanks to:
Vienna University of Economics and Business Powered By FusionForge