[R] memory error in for loop

Gabor Grothendieck ggrothendieck at gmail.com
Sun Mar 7 18:08:11 CET 2010


Try the RpgSQL package and see if you get the same problem.

On Fri, Mar 5, 2010 at 10:08 PM, Peter <ptittmann at gmail.com> wrote:
> hi,
>
> I have been attempting to run this script and am getting some strange
> results. The script connects to a database and retrieves a series of tables,
> using sequential sql statements. I have tested all of the sql statements in
> the PostGreSQL terminal and they all return the desired results. I place
> each table into a list and run a FOR loop for 'i' in the list. The script
> generates the first map perfectly and begins to draw the second and then
> crashes in the middle of creating the second plot. I am suspicious that
> somehow i have a problem in my for loop that results in memory overload but
> I have been struggling to figure it out all day with no success. I have
> included below the for loop in the code and the beginning of the error
> message that is produced in the terminal. Any suggestions would be most
> welcome.
>
> thanks in advance,
>
> peter
>
> script:
>
> #create a list of results tables
> matrixlist <- list(r_baseline, r_badlce, r_cblend, r_fedforest, r_ffv,
> r_hiencrop, r_loencrop, r_maxfeed) #par(mfcol= c(5,5))
> for (i in matrixlist){
>                                        ptable<-i[,-1]#create plot matrix w/o
> price point column
>
>  ptable [is.na(ptable)] <- 0 #convert NA values to 0
>                                maxval<-max(ptable) #create volume axis
>  interval<-ceiling(maxval)/27
>  mgy<- seq(0,ceiling(maxval), by=interval)
>    fprice <- c(i$price_point)#create price point axis
>  #pdf(paste(i,"fuel_pw.pdf", sep=""), bg="white")
>  matplot(ptable, fprice, type="l", col= rainbow(length(names(i))))
>  #rm(i,ptable, fprice, maxval, interval, mgy)
>  dev.off()
> }
>
> and the resulting error:
>
> +   fprice <- c(i$price_point)#create price point axis
> +   #pdf(paste(i,"fuel_pw.pdf", sep=""), bg="white")
> +   matplot(ptable, fprice, type="l", col= rainbow(length(names(i))))
> +   rm(i,ptable, fprice, maxval, interval, mgy)
> +   dev.off()
> + }
> matplot: doing 17 plots with  col= ("#FF0000FF" "#FF5500FF"
> "#FFAA00FF" "#FFFF00FF" "#AAFF00FF" "#55FF00FF" "#00FF00FF"
> "#00FF55FF" "#00FFAAFF" "#00FFFFFF" "#00AAFFFF" "#0055FFFF"
> "#0000FFFF" "#5500FFFF" "#AA00FFFF" "#FF00FFFF" "#FF00AAFF"
> "#FF0055FF") pch= ("1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "a" "b" "c"
> "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t"
> "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K"
> "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z") ...
>
> matplot: doing 23 plots with  col= ("#FF0000FF" "#FF4000FF"
> "#FF8000FF" "#FFBF00FF" "#FFFF00FF" "#BFFF00FF" "#80FF00FF"
> "#40FF00FF" "#00FF00FF" "#00FF40FF" "#00FF80FF" "#00FFBFFF"
> "#00FFFFFF" "#00BFFFFF" "#0080FFFF" "#0040FFFF" "#0000FFFF"
> "#4000FFFF" "#8000FFFF" "#BF00FFFF" "#FF00FFFF" "#FF00BFFF"
> "#FF0080FF" "#FF0040FF") pch= ("1" "2" "3" "4" "5" "6" "7" "8" "9" "0"
> "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
> "r" "s" "t" "u" "v" "w" "x" "y" "z" "A" "B" "C" "D" "E" "F" "G" "H"
> "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y"
> "Z") ...
>
> Garbage collection 3 = 2+0+1 (level 0) ...
> 3.6 Mbytes of cons cells used (38%)
> 0.8 Mbytes of vectors used (13%)
> *** glibc detected *** /usr/lib/R/bin/exec/R: double free or
> corruption (!prev): 0x094f8c38 ***
> ======= Backtrace: =========
> /lib/i686/cmov/libc.so.6[0xb7486824]
> /lib/i686/cmov/libc.so.6[0xb74880b3]
> /lib/i686/cmov/libc.so.6(cfree+0x6d)[0xb748b0dd]
> /usr/lib/libpq.so.5(PQclear+0xf6)[0xb6e53976]
> /home/ptittmann/R/i486-pc-linux-gnu-library/2.10/RdbiPgSQL/libs/RdbiPgSQL.so(PgSQLclearResult+0x25)[0xb6fc2665]
> /usr/lib/R/lib/libR.so(R_RunWeakRefFinalizer+0x161)[0xb76721f1]
> /usr/lib/R/lib/libR.so[0xb7672357]
> /usr/lib/R/lib/libR.so[0xb76743fe]
> /usr/lib/R/lib/libR.so(Rf_allocVector+0xb8)[0xb7675628]
> /usr/lib/R/lib/libR.so(Rf_usemethod+0x41d)[0xb768306d]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list