[R] Error with repeat lines() in function

Sean Davis sdavis2 at mail.nih.gov
Fri Sep 24 17:48:41 CEST 2004


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?

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)
}




More information about the R-help mailing list