[R] Rgui 1.5.1 crashes constantly with the following script

Jorge de la Vega jvega at banxico.org.mx
Fri Jun 21 19:56:29 CEST 2002


I am not sure if something is wrong with my programming or is a bug of chron
or something else.
In the following script, db is a large dataframe (dim(db)=c(60698,14)), then
I select a very small part for a specific date and compute some basic
statistics. date.base is a chron object

  foo<-function(db,date.base){
	date.base<-as.numeric(date.base) #convert to number
      if(dim(base[1])==0)return(c(date.base,rep(0,8)))
      fe.con<-as.numeric(chron(as.character(db$f.con),format="y/m/d")) #make
chron object and then numeric
      vig<-db[fe.con==f.base,] #subset the database
      if(dim(vig)[1]==0)return(c(date.base,rep(0,8))) #if not records return
0 stats

     #sample stats
      num.oper<-as.vector(apply(tapply(vig$mnt.base,vig$oper,length),1,c) )

mb.oper<-as.vector(apply(tapply(vig$mnt.base,vig$oper,sum,na.rm=T),1,c))

p.p.pond<-as.vector(unlist(lapply(tapply(vig$mnt.base*vig$plazo,vig$oper,c),
sum,na.rm=T))/mb.oper)

      rm(vig,fe.con) #clean memory

out<-c(date.base,sum(num.oper),num.oper,sum(mb.oper)/1000,mb.oper/1000,plazo
.prom.pond)
      return(as.vector(out))
}

The function foo alone works fine
> foo(db,yesterday)
[1]   53.0000   21.0000   32.0000 3915.0680  310.0350 3605.0330  176.0825
26.4649

But when I include the function in a for,

foo2<-function(db,dates){
    n<-length(dates)
    z<-matrix(0,nrow=n,ncol=9)
    for(i in 1:n)z[i,]<-estad.basicas(db,dates[i])
    return(z)
}

then I sometimes have the output and sometimes a crash. It doesn´t depend on
the length of dates, I can run the function with 30 or more fine but then if
I run it again with only two or three dates it crashes Rgui. Sometimes I
have a window error from  Virtual C++, that I am not sure is part of the
system.

Thanks for your suggestions.

Jorge de la Vega

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list