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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Sarah Brockhaus
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

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

luke-tierney
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
>
> ______________________________________________
> [hidden email] 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:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

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

luke-tierney
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, [hidden email] 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
>>
>> ______________________________________________
>> [hidden email] 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:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] 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.