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 TRUE. This function is used in splinefun and several other interpolation functions in R. In a microsimulation model, I am using splinefun to smooth a large amount (n > 100,000) of data points of the form (x, f(x)). Here, x is a simulated vector of positive-valued scalers, and f(x) is some function of (x). With an n that large, there are often some replications of pseudo-randomly generated values (i.e., not all values of x are unique). My understanding is that splinefun gets rid of ties in the x values. That is not a problem for me, but, because of the new default, I get a warning message printed each time (below)
“在regularize.values(x,y,关系,missing(ties))中:折叠为唯一的'x'值”
有没有办法将stats::regularize.values函数的warn.collapsing参数的默认值改回F?还是我可以以某种方式禁止该警告?这很重要,因为它嵌入了很长的微仿真代码中,当我对其进行更新时,我经常会遇到错误。因此,我不能只是忽略警告消息。
我尝试使用形式化功能。我能够获取默认的print参数stats::regularize.values,但是当我尝试使用该alist函数分配新值时,它说没有对象'stats'。
小智 7
我也遇到了这个问题,并通过添加ties=min到 的参数列表来修复它splinefun()。的值missing(ties)现在被传递warn.collapsing给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 /约.R
另请参阅:
https ://cran.r-project.org/doc/manuals/r-release/NEWS.html
并搜索regularize.values().
参考这篇文章
regularize.values像这样包装你的电话:
withCallingHandlers(regularize.values(x), warning = function(w){
if (grepl("collapsing to unique 'x' values", w$message))
invokeRestart("muffleWarning")
})
Run Code Online (Sandbox Code Playgroud)
工作示例(改编自上面的链接以调用函数):
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
805 次 |
| 最近记录: |