axelniemeyer
axelniemeyer

Reputation: 167

Suppressing error messages from external functions

I am using the function FixedPoint() from the package FixedPoint for some computations in R. Even if a fixed point of some function cannot be found, FixedPoint() still returns output (indicating the error) and, in addition, returns an error message. I want to suppress any such additional error messages from being printed. Neither try(), nor suppressWarnings(), nor suppressMessages() seem to work. Please find an example below that produces such an additional error message.

library(FixedPoint)

ell=0.95
delta=0.1 
r=0.1
lambda=1
tH=1
tL=0.5
etaL=1
etaH=1


sys1=function(y){
  A=y[1]
  B=y[2]

  TA=(etaM*(1-exp(-(lambda*A+lambda*(A+B)+2*delta)*tL))-2*lambda*A^2-lambda*A*B)/2/delta
  TB=(etaM*exp(-(lambda*A+lambda*(A+B)+2*delta)*tL)*(1-exp(-(lambda*(A+B)+2*delta)*(tH-tL)))-lambda*B^2-lambda*A*B)/2/delta

  return(c(TA,TB))
}

FixedPoint(sys1,c(1.90,0.04))

Upvotes: 2

Views: 139

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226182

This seems to work:

cc <- capture.output(ff <- FixedPoint(sys1,c(1.90,0.04)),type="message") 

where ff now holds the output you want. (Alternately, you could wrap capture.output(...) in invisible() rather than assigning its return value to a variable.)

The problem seems to be that the error message emanates from an un-silence-d try() clause within the package code.

Upvotes: 3

Related Questions