[R] Error with repeat lines() in function

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Sep 24 18:05:13 CEST 2004


Sean Davis wrote:

> I have a function that does some plotting.  I then add lines to the  
> plot.  If executed one line at a time, there is not a problem.  If I  
> execute the function, though, I get:
> 
> Error in ans[[1]] : subscript out of bounds
> 
> This always occurs after the second lines command, and doesn't happen  
> with all of my data points (some do not have errors).  Any ideas?

Please give an example how to produce the error,
i.e. specify a very small toy example (including generated data and the 
call to your function).
Many people on this list are quite busy these days and don't want to 
think about how to call your function and invent an example ...

Uwe Ligges



> Thanks,
> Sean
> 
> 
>  function(x,annot,rat1,rat2,rf,...) {
>     par(las=2)
>     wh <- which(annot[,5]==x)
>     xmax <- max(annot[wh,4])
>     xmin <- min(annot[wh,3])
>     chr <- annot[wh,2][1]
>     wh.rf <- rf$chrom==as.character(chr) & rf$txStart>xmin &  rf$txEnd<xmax
>     par(mfrow=c(2,1))
>     plot(annot[wh,3],rat1[wh],type="l",xlab="",ylab="log2  
> Ratio",main=x,...)
>     points(annot[wh,3],rat1[wh])
>     apply(rf[wh.rf,],1,function(z) {
>       browser()
>       if (z[4]=="+") {
>         color <- 'green'
>         yoffset=1
>       } else {
>         color <- 'red'
>         yoffset=-1
>       }
>        lines(list(x=c(z[5],z[6]),y=c(-2-yoffset/10,-2-yoffset/ 
> 10)),lwd=2,col=color)
>        lines(list(x=c(z[5],z[6]),y=c(-2-yoffset/10,-2-yoffset/ 
> 10)),lwd=2,col=color)
>     })
>     abline(h=0,lty=2)
> }
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html




More information about the R-help mailing list