Rewrite a function in locked env

226 Views Asked by At

Using pvclust::pvclust , I got an error

Error in solve.default(crossprod(X, X/vv)) : Lapack routine dgesv: system is exactly singular: U[2,2] = 0 Calls: ... pvclust.merge -> lapply -> FUN -> msfit -> solve -> solve.default Execution halted

I don't want stop analysis even if crossprod(X, X/vv) be singular matrix, so I tried to insert an if {...} block in pvclust::msfit to check whether crossprod(X, X/vv) is singular or not by matrixcalc::is.singular.matrix, and if it is so, return NA and continue.

After saved my.msfit.R which contain msfit which incerted if(!is.singular.matrix(...)) {...}else{...} in original pvclust::msfit,

methods::insertSource('/myFuncDir/my.msfit.R',package="pvclust",functions='msfit')

But I got error below

Error in assign(this, thisObj, envir = envwhere) : cannot change value of locked binding for 'msfit' In addition: Warning message: In methods::insertSource(filename, package = "pvclust", functions = "msfit", : cannot insert these (not found in source): "msfit"

Is there any solution? Should I request of the author of the pvclust package?

== Below added after posting ==

An accurate advice was given in comments to use try/catch syntax, but I don't think it will give me solution.

Concerning my poor English skill, I present a toy sample which tells the situation.

fun.a <- function(a1,a2,a3,a4){
  sum1 <- a1 + a2
  sum2 <- a2 + a3
  sum3 <- a3 + a4
  return(list(sum1,sum2,sum3))
 }

fun.a(1,2,3,'Char')

Because that the sum3 will be an error, so fun.a(1,2,3,'Char') returns error.

But, I want to return

List [sum1, sum2, NaN]

If I use tryCatch(...,error=expr), sum1 to sum3(actually, solve(...)in pvclust::msfit) should be wrapped. But, fun.a(msfit) is inner function of locked package(pvclust).

0

There are 0 best solutions below