[R] Device problems in a loop.

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Mar 28 16:12:52 CET 2008


This is an instance of FAQ Q7.22: you haven't plotted anything and so the 
device is not yet open.

On Fri, 28 Mar 2008, Todd Remund wrote:

>
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list