How to suppress warnings from stats:::regularize.values?

后端 未结 2 516
青春惊慌失措
青春惊慌失措 2020-12-17 02:27

In newer versions of R (I have 3.6 and previously had 3.2), the stats::regularize.values function has been changed to have a default value of warn.collapsing as

相关标签:
2条回答
  • 2020-12-17 02:56

    I had this problem too, and fixed it by adding ties=min to the argument list of splinefun(). The value of missing(ties) is now passed as warn.collapsing to regularize.values().

    https://svn.r-project.org/R/trunk/src/library/stats/R/splinefun.R
    https://svn.r-project.org/R/trunk/src/library/stats/R/approx.R

    Also see: https://cran.r-project.org/doc/manuals/r-release/NEWS.html and search for regularize.values().

    0 讨论(0)
  • 2020-12-17 03:04

    Referencing this article

    Wrap your call of regularize.values like this:

    withCallingHandlers(regularize.values(x), warning = function(w){
      if (grepl("collapsing to unique 'x' values", w$message))
       invokeRestart("muffleWarning")
    })
    

    Working example (adapted from the above link to call a function):

    f1 <- function(){
      x <- 1:10
      x + 1:3
    }
    
    f1()
    
    # if we just call f1() we get a warning
    Warning in x + 1:3 :
      longer object length is not a multiple of shorter object length
     [1]  2  4  6  5  7  9  8 10 12 11
    
    
    withCallingHandlers(f1(), warning=function(w){invokeRestart("muffleWarning")})
     [1]  2  4  6  5  7  9  8 10 12 11
    
    0 讨论(0)
提交回复
热议问题