Hi all,

     I'm having trouble saving graphics output from within a loop, and I
can't figure out a solution.  I'd like to produce and save lots of
individual plots for inspection, so I set up the following script:

library( lattice )
wd = "~/Documents/PPM/"
ppm = read.table( paste( wd, "ppm_summary.txt", sep = "" ), sep = "\t",
header = TRUE )
ppm$Trial = as.factor( ppm$Trial )

for ( ID in levels( ppm$Patient ) ){
    patient_data = ppm[ ppm$Patient == ID, ]
    dir.create( paste( wd, ID, sep = "" ) )
    for ( trial in ( levels( ppm[ ppm$Patient == ID, ]$Trial ) ) ){
        trial_data = patient_data[ patient_data$Trial == trial, ]
        trial_str = sprintf( "%03d", as.integer( trial ) )
        path = paste( wd, ID, "/", trial_str, ".png", sep = "" )
        cat( path, "\n" )
        png( path )
        xyplot( PupilArea ~ Offset, data = trial_data )
        dev.off()
    }
}

     Everything runs, the cat() command displays output to the console, but
no files are created.  However, if I interrupt the script with control-C and
execute the png(), xyplot(), and dev.off() commands manually, the
appropriate plot image files are written based on the correct data.  That
is, everything from data subsetting to plotting works fine except when the
loop is actually running.  I've tried swapping png() for bitmap(),
Sys.sleep()ing R at various stages, and some other things with no success.
What am I missing?  Thanks in advance,

Dave

-- 
Post-doctoral Fellow
Neurology Department
University of Iowa Hospitals and Clinics
davideugenewarren@gmail.com

	[[alternative HTML version deleted]]

