Re: [R] loop causes syntax error in print() Duncan Murdoch wrote: > On 7/3/2007 1:59 AM, Ivan Baxter wrote: >> I am having trouble printing a table out to the GUI display when the  >> table is created and printed within a loop. >> >> I get a "Error: syntax error message" >> >> If I comment out the print statement, the loop runs fine and I can  >> print out the last iteration of the table. > > You should simplify your loop until it's something you can post for us  > to try.  Chances are you'll notice the error when you do that, but if  > not, someone else will be able to tell you what's going on. > > Without a reproducible example, it's more or less hopeless. > > Duncan Murdoch Right- well I did as you suggested and seem to have fixed the problem. The problem appeared to be that some carriage returns were not  registering in the Mac Os X R editor. So even though it looked like it  was on a new line, it wasn't. It wasn't a line wrap issue, these were  actually returns that I had hit that just weren't registering. I had one  chunk of code which showed what I thought was the problem when R  crashed. When I opened up the script again after restarting, the problem  disappeared, so somehow the returns started to be seen. thanks for your help. Ivan > >> >> ...[multiple loops and calculations ending with.....]... >> >> +             print(paste(mutType,"sim",sim,"hmm",hmm))       >> +             # print(acctab[,10:15]) >> +                +             nummod <- nummod +1 >> +         }  #end hmmMats loop >> +         }  #end tmats loop   +         }  #end mut type loop >> [1] "dup sim Imod hmm Jmod" >> >>  > print(acctab[,10:15]) >>     hitrate falsepos   multrate      avghit avgmiss avgfalsepos >> 1 0.0000000        1        NaN         NaN       2          NA >> 2 1.0000000        0 0.00000000    5.333333     NaN          NA >> 3 0.0000000      NaN        NaN         NaN       9          NA >> 4 0.7777778        0 0.00000000   15.571429      11          NA >> 5 1.0000000        0 0.00000000   24.083333     NaN          NA >> 6 1.0000000        0 0.07692308   64.538462     NaN          NA >> 7 1.0000000        0 0.39207048 1088.454846     NaN          NA >> >> you can see that >> a) the print statement above it works >> b) the print command works with this table >> >> but if I uncomment it and try to run the loops again..... >> >> +             print(paste(mutType,"sim",sim,"hmm",hmm))          >>               print(acctab[,10:15]) >> Error: syntax error >>  >         >                 >             nummod <- nummod +1 >>  >         }  #end hmmMats loop >> Error: syntax error >>  >         }  #end tmats loop   Error: syntax error >>  >         }  #end mut type loop >> Error: syntax error >> >> >> I have tried print.data.frame, but that doesn't work either.... >> >> >> Any suggestions would be appreciated  (session info below) >> >> >> Ivan >> >> >>  > sessionInfo() >> R version 2.5.1 (2007-06-27) >> i386-apple-darwin8.9.1 >> >> locale: >> C >> >> attached base packages: >> [1] "stats"     "graphics"  "grDevices" "utils"     "datasets"   >> "methods"   "base"  > --  ************************************************************** Ivan Baxter Research Scientist Bindley Bioscience Center Purdue University Office: Hort 305 765-543-7288 ibaxter@purdue.edu ______________________________________________ R-help@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 and provide commented, minimal, self-contained, reproducible code.