Skip to content

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

3 messages · Sarah Brockhaus, Luke Tierney

#
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
#
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:

            

  
    
1 day later
#
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: