[R] try()-function does not catch error in BATCH-job if Matrix is loaded

luke-tierney at uiowa.edu luke-tierney at uiowa.edu
Tue Jan 8 23:40:19 CET 2013


The work-around was actually put in plae prior to the release of R
2.15.2, so updating your R to the current released version will
resolve this.

Best,

luke

On Mon, 7 Jan 2013, luke-tierney at uiowa.edu wrote:

> This is due to long-staning issue in methods internals, which are
> involved because loading Matrix shadows base::mean with Matrix::mean.
> A work-around has been in place in R_devel for some time; a proper fix
> may come at some point in the future. So if your real code doesn't
> need the moficied mean from Matrix you can use base::mean; otherwise
> you will have to use an R-devel snapshot.
>
> Best,
>
> luke
>
> On Mon, 7 Jan 2013, Sarah Brockhaus wrote:
>
>> Hello,
>> 
>> In my simulation I use the try()-function to catch possible errors when 
>> fitting models. I run the simulationon a Linux-server using the command " R 
>> CMD BATCH nameOfFile.R &".  When executing the code as batch-job I get the 
>> problem that the execution is halted without giving an error message. But 
>> when I run the code interactivly the error is catched by try() as it would 
>> be expected.
>> 
>> The problem is somewhat strange as it only occurs when the code is executed 
>> as a batch-job and when the package "Matrix" is loaded.
>> 
>> I wrote a small example reproducing the error. (In my code the error occurs 
>> in mgcv:::fixDependence, which looks like the code I'm using below in order 
>> to get a small reproducible example. I realized that the code  makes no 
>> sense...)
>> 
>> ######################################
>> library(Matrix)
>> 
>> R <- matrix(abs(rnorm(25)), 5, 5)
>> r0 <- r <- nrow(R)
>> 
>> # while-loop produces error that should be catched by the function try()
>> try(
>> while (mean(R[r0:r, r0:r]) > 0) r0 <- r0 - 1
>> )
>> 
>> # so "Hello" should be printed
>> print("Hello")
>> ######################################
>> 
>> I use R version 2.15.1 (2012-06-22) on a x86_64-pc-linux-gnu (64-bit) 
>> platform.
>> 
>> I would be grateful for help.
>> 
>> Best regards,
>> Sarah Brockhaus
>> 
>> PHD-student
>> Department of Statistics
>> University of Munich
>> 
>> ______________________________________________
>> 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.
>> 
>
>

-- 
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu




More information about the R-help mailing list