I would like my program to load variables x,y,x from a file 'myFile.r' but if this file does not exist, I want my program to create/initialize x,y,z. Does anyone know how to do this? Thank you very much. Francisco J. Molina
On Wed, Feb 11, 2004 at 07:22:00PM -0800, Francisco J Molina wrote:> > I would like my program to load variables x,y,x from a file 'myFile.r' but > if this file does not exist, I want my program to create/initialize x,y,z. > > Does anyone know how to do this??file.info # as help.search("file") would have revealed Hth, Dirk -- The relationship between the computed price and reality is as yet unknown. -- From the pac(8) manual page
You can adapt this to your situation: z <- try( read.table("myfile", header=T) ) if (class(z) == "try-error") z <- data.frame(x=1,y=2,z=3) You may also be interested in the silent= arg of try. See ?try Date: Wed, 11 Feb 2004 19:22:00 -0800 From: Francisco J Molina <fjmolina at ams.ucsc.edu> To: r-help <r-help at stat.math.ethz.ch> Subject: [R] How to detect whether a file exists or not? I would like my program to load variables x,y,x from a file 'myFile.r' but if this file does not exist, I want my program to create/initialize x,y,z. Does anyone know how to do this? Thank you very much. Francisco J. Molina