[R] Rprof causing R to crash

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Fri Dec 14 14:22:31 CET 2012


Uwe,

I am unfortunately not able to upgrade to R 2.15.2 right now, but I have 
seen a similar problem with several older R versions. If you want to 
test with a shorter script, you can try the lines below. These provoke a 
crash from a fresh R session on my machine (R 2.15.1 Windows 7):

Rprof()
z = 1
for (i in 1:1e8) z = z+1/i

This runs without problems without the call to Rprof(). I was far from 
using all my memory with this call, but you could also check with a 
higher number of loops in case you can run these lines and it is somehow 
memory related. Just for comparison, I tried 1e9 loops after a call to 
Rprof() on one of our Linux servers (R 2.14.0) without any problems.

Jon

On 12-Dec-12 17:06, Uwe Ligges wrote:
>
>
> On 12.12.2012 00:05, Marian Talbert wrote:
>> I'm trying to use Rprof() to identify bottlenecks and speed up a 
>> particullary
>> slow section of code which reads in a portion of a tif file and compares
>> each of the values to values of predictors used for model fitting.  I've
>> written up an example that anyone can run.  Generally temp would be a
>> section of a tif read into a data.frame and used later for other 
>> processing.
>> The first portion which just records the time works in about 6 
>> seconds the
>> second part causes RGui to immediately close with no error or 
>> warning.  Any
>> advice on how to get Rprof to work or how to speed up this code would be
>> greatly appreciated.  I'm using Windows 7 (which might be my problem) 
>> and R
>> version 2.15.0.
>
> The problem is rather the R version: I cannot reproduce errors with a 
> recent R.
>
> Uwe Ligges
>
>
>>
>> CalcMESS<-function(tiff.entry,pred.vect){
>> f<-sum(pred.vect<tiff.entry)/length(pred.vect)*100
>>                if(is.na(f)) return(NA)
>>                if(f==0)
>> return((tiff.entry-min(pred.vect))/(max(pred.vect)-min(pred.vect))*100)
>>                if(0<f & f<=50) return(2*f)
>>                if(50<=f & f<100) return(2*(100-f))
>>                if(f==100)
>> return((max(pred.vect)-tiff.entry)/(max(pred.vect)-min(pred.vect))*100)
>>                else return(NA)
>> }
>>
>> train.dat <- 
>> data.frame(a=runif(200),b=runif(200),c=runif(200),d=runif(200))
>> temp <-
>> data.frame(a=runif(130000),b=runif(130000),c=runif(130000),d=runif(130000)) 
>>
>> pred.rng<-temp
>> vnames.final.mod <- names(train.dat)
>> nvars.final <- length(vnames.final.mod)
>>
>> start.time<-Sys.time()
>>               for(k in 1:nvars.final){
>>
>> pred.range<-train.dat[,match(vnames.final.mod[k],names(train.dat))]
>>
>> pred.rng[,k]<-mapply(CalcMESS,tiff.entry=temp[,match(vnames.final.mod[k],names(temp))],MoreArgs=list(pred.vect=pred.range)) 
>>
>>                           }
>> Sys.time()-start.time
>>
>>
>> Rprof("C:\\temp\\mapply.out")
>>               for(k in 1:nvars.final){
>>
>> pred.range<-train.dat[,match(vnames.final.mod[k],names(train.dat))]
>>
>> pred.rng[,k]<-mapply(CalcMESS,tiff.entry=temp[,match(vnames.final.mod[k],names(temp))],MoreArgs=list(pred.vect=pred.range)) 
>>
>>                           }
>> Rprof(NULL)
>>
>>
>>
>> -- 
>> View this message in context: 
>> http://r.789695.n4.nabble.com/Rprof-causing-R-to-crash-tp4652846.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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