[R] Device problems in a loop.

From: Todd Remund <tkremund98_at_hotmail.com>
Date: Fri, 28 Mar 2008 08:09:33 -0600

I have tried the following code to plot and save many box plots in files. The code works by itself, but does not run in a loop. The error indicates that there is no device. The error is printed below the code.

Code:

for(i in 1:len)
{

    A = as.numeric(delta[Delta[i,1]])
    B = as.numeric(delta[Delta[i,2]])
    C = as.numeric(delta[Delta[i,3]])
    D = as.numeric(delta[Delta[i,4]])

    data <- scan(filenames52[i], quiet=TRUE)     data <- matrix(data, ncol=8)
    grp <- c('K1','K2','K3','K4','N','NBC','NE','NEBC')     grp <- as.factor(rep(grp, each=200))     bwplot(c(data)~grp, ylab='MSE', pch=19,
        par.settings = list(plot.symbol = list(pch = "+")),
        main=eval(substitute(expression(paste('        ', delta[phi[1]], 
        " = ", tval, '  |  ',
        delta[phi[2]], ' = ', tval2, '  |  ',
        delta[theta[1]], ' = ', tval3, '  |  ',
        delta[theta[2]], ' = ', tval4,)),
        list(tval=A, tval2=B, tval3=C, tval4=D))))

    dev.print(file=filenameplot[i], device=png, width=600, height=480)     dev.off()
}

Error is:

Error in dev.print(file = filenameplot[i], device = png, width = 600, :   no device to print from

I cannot figure out why the loop won't work but setting i <- 1 or 2 ... and then running the code inside the loop will work. Does anyone have any suggestions.

        [[alternative HTML version deleted]]



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. Received on Fri 28 Mar 2008 - 14:19:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 28 Mar 2008 - 16:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive