Is it possible to use an old version of 'stats' package in R?

烈酒焚心 提交于 2020-04-30 10:47:15

问题


Is it possible to use an old version of the stats package in R?

The function stats:::regularize.values causes me warnings and errors in the last R version (any version >3.5). I have no possibility to get back to an old R version. I have no clue where the regularize.values function is called in my code since I use several functions, some of them from different R packages. I've tried to change the call to regularize.values in my code by doing

assignInNamespace("regularize.values", regularize.values.old.version, ns = "stats")

But I got the error:

Error in assignInNamespace("regularize.values", regularize.values.OV,  : 
  locked binding of ‘regularize.values’ cannot be changed

Thanks in advance for your suggestions!


回答1:


You can try this:

assignInNamespace("regularize.values", regularize.values.OV, 
                  ns="stats", envir = as.environment("package:stats"))

However, it will only work if the error is not thrown by a package that depends on the already-loaded stats


Therefore, a working solution should be:

assignInNamespace("regularize.values", function(x, y, ties) {
    x <- xy.coords(x, y)
    y <- x$y
    x <- x$x
    if(any(na <- is.na(x) | is.na(y))) {
    ok <- !na
    x <- x[ok]
    y <- y[ok]
    }
    nx <- length(x)
    if (!identical(ties, "ordered")) {
        o <- order(x)
    x <- x[o]
    y <- y[o]
    if (length(ux <- unique(x)) < nx) {
        # if (missing(ties))
        # warning("collapsing to unique 'x' values")
        y <- as.vector(tapply(y,match(x,x),ties))
        x <- ux
        stopifnot(length(y) == length(x))
    }
    }
    list(x=x, y=y)
}, ns="stats", envir = as.environment("package:stats"))


来源:https://stackoverflow.com/questions/60934150/is-it-possible-to-use-an-old-version-of-stats-package-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!