R Aborting Only used 200MB of Memory

Hi all. RStudio is constantly aborting whenever I run a custom function that manipulates a dataframe and replaces it with another dataframe. (i.e. Dataframe1=CustomFunction(Dataframe1) but RStudio aborts whenever I run the function. When I run mem_used it shows I am only using 200MB of memory, far below the limit. If anyone could please shed some light on the situation, I would appreciate it.

Thanks

Use debug() or browser() to identify the code statement that causes the abort.

There isn't a problem with the function itself. The function runs fine. The assignment to the dataframe is where R aborts, but other times it works fine. I just do not understand why R is aborting. I would usually think I was running out of RAM, but I'm only using 200MB.

Let's be clear, are you saying that the above always aborts. And

CustomFunction(Dataframe1)

Never aborts? and prints output to the console?

Yes, that is correct. Very strange

Unfortunately I think that without access to the function code it will be impossible for anyone to debug/diagnose for you.

Here is the function. There are other custom functions that this function calls, but all the dependencies run 100% good all the time. Here is the function. I apologize for the length.

ShortSim=function(SimmedSchedule,Year,runs){
rm(FinalR)
Schedule=SimmedSchedule
rm(SimmedSchedule)
NotPlayed=Schedule %>%
  filter(Simmed==1)
Schedule=Schedule %>%
  filter(Simmed==0)

NotPlayed$VisitingTeam=str_trim(NotPlayed$VisitingTeam,side = "both")
NotPlayed$HomeTeam=str_trim(NotPlayed$HomeTeam,side = "both")

for(i in 1:nrow(NotPlayed)){
  tryCatch({
    message("Simulating ",paste(NotPlayed[i,3]," @ ",NotPlayed[i,2]," on ",NotPlayed[i,1],"   *** ",round((i/nrow(NotPlayed))*100,digits = 1),"% Complete ***",sep = ""))
    hold=SimGame(NotPlayed[i,3],NotPlayed[i,2],runs)
    #Check to make sure aggregate results from sims to not come out equal which would result in a tie. If they do, chose randomly
    if(hold[[1]] == hold[[2]]){
      if(runif(1)>=.5){
        hold[[1]]=1
        hold[[2]]=0
      }else{
        hold[[1]]=0
        hold[[2]]=1
      }
    }
    NotPlayed[i,5]=hold[[1]]
    NotPlayed[i,4]=hold[[2]]
  },error=function(e){})
}
beep(2)

NotPlayed=NotPlayed[complete.cases(NotPlayed),]
NotPlayed=NotPlayed %>%
  select("date","HomeTeam","VisitingTeam","HomeScore","VisitingScore","Neutral")
NotPlayed$Simmed=1
Schedule=Schedule %>%
  select("date","HomeTeam","VisitingTeam","HomeScore","VisitingScore","Neutral")
Schedule$Simmed=0
Schedule=Schedule[complete.cases(Schedule),]
SimmedSchedule=rbind.data.frame(Schedule,NotPlayed)
rm(NotPlayed)
SimmedSchedule=SimmedSchedule %>%
  arrange(date)
beep(1)
#FinalR=ApplyModels(CalculateConfChamp(CalculateRPI(SimmedSchedule)))
SimmedSchedule=CalculateRPI(SimmedSchedule)
#write.csv(Result,"F:\\Result.csv")
rm(SimmedSchedule)
gc()
beep(2)
#Result=read.csv("F:\\Result.csv")
SimmedSchedule=CalculateConfChamp(SimmedSchedule)
#rm(Result)
FinalR=ApplyModels(SimmedSchedule)
#rm(ConfR)

#rm(ConfR)
#rm(Result)
#rm(Schedule)
beep(2)
 return(FinalR) 
}

I've tried various gimmicks such as writing it to a CSV, bringing it back and removing various things throughout the function. That's why there are so many things commented out.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.