Skip to content
Prev 56228 / 398500 Next

Error with repeat lines() in function

The problem was is that you were not return a value from the apply
function.  It was trying to store the result of the apply into an array and
there was no value.

See the line I added in your function.
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com
+1 (513) 723-2929


                                                                                                                                           
                      Sean Davis                                                                                                           
                      <sdavis2 at mail.nih.gov        To:       Uwe Ligges <ligges at statistik.uni-dortmund.de>                                 
                      >                            cc:       r-help <r-help at stat.math.ethz.ch>                                             
                      Sent by:                     Subject:  Re: [R] Error with repeat lines() in function                                 
                      r-help-bounces at stat.m                                                                                                
                      ath.ethz.ch                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      09/24/2004 13:09                                                                                                     
                                                                                                                                           
                                                                                                                                           




Here is an example that seems to reproduce the error:

rf1 <- matrix(sort(abs(round(runif(4)*1000000))),nrow=1)
annot1 <- sort(abs(round(runif(193)*1000000)))
annot2 <- annot1 + 70
annot3 <- cbind(annot1,annot2)
rat2 <- rnorm(193)
rat1 <- rnorm(193)
plotter <-
function(annot,rat1,rat2,rf1,...) {
     par(las=2)
     xmax <- max(annot[,2])
     xmin <- min(annot[,1])
     par(mfrow=c(2,1))
     plot(annot[,1],rat1,type="l",xlab="",ylab="log2 Ratio",...)
     points(annot[,1],rat1)
     apply(rf1,1,function(z) {
       if (z[4]=="+") {
         color <- 'green'
         yoffset=1
       } else {
         color <- 'red'
         yoffset=-1
       }

lines(list(x=c(z[1],z[4]),y=c(-2-yoffset/10,-2-yoffset/
10)),lwd=2,col=color)

lines(list(x=c(z[2],z[3]),y=c(-2-yoffset/10,-2-yoffset/
10)),lwd=4,col=color)

1     #  fake a return value

     })
     abline(h=0,lty=2)
   }
plotter(annot3,rat1,rat2,rf1)
Error in ans[[1]] : subscript out of bounds

Enter a frame number, or 0 to exit
1:plotter(annot3, rat1, rat2, rf1)
2:apply(rf1, 1, function(z) {
Selection: 0
On Sep 24, 2004, at 12:05 PM, Uwe Ligges wrote:

            
______________________________________________
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