【发布时间】:2015-11-05 09:41:48
【问题描述】:
程序:Mac OSX 的 R 3.2.1
IDE:RStudio
输出:rmkd > html
包装:“心理”
功能:alpha()
问题:
在使用alpha(data, na.rm=F, check.keys=F, delete=F) 时,由于部分输入数据是负相关的,并且因为我有 check.keys = FALSE,所以我收到以下消息:
部分项目XXX与总量表呈负相关, 可能应该颠倒过来。为此,请再次运行该函数 'check.keys=TRUE' 选项
问题:
我的 check.keys 是故意设置的。完全理解警告的含义,主要是出于审美和教育原因,我如何在输出中抑制它?
目前的尝试:
1. 我试过suppressWarnings() & suppressMessages()。
2. 我试过invisible() & sink(., type="message")。
3. 在 Rmd 块中,我试过了:```{r warning=F, message=F}
4.探索print(alpha)我发现了我认为的起源。也许有人知道如何抑制这部分代码? :
`p1 <- principal(x)
if (any(p1$loadings < 0)) {
if (check.keys) {
warning("Some items were negatively correlated with total scale and were automatically reversed.\n This is indicated by a negative sign for the variable name.")
keys <- 1 - 2 * (p1$loadings < 0)
}
else {
warning("Some items were negatively correlated with the total scale and probably should be reversed. To do this, run the function again with the 'check.keys=TRUE' option")
cat("Some items (", rownames(p1$loadings)[(p1$loadings < 0)], ") were negatively correlated with the total scale and probably should be reversed. To do this, run the function again with the 'check.keys=TRUE' option")
}
}`
谢谢!
【问题讨论】:
-
这应该通知代码的开发者,他们的函数会做坏事(不应该有
cat)。 -
康拉德是正确的。让我知道这个问题很有帮助。它现在已在 psych 1.5.8 中修复(希望本周末来到 CRAN)。
-
我做了一个小猴子补丁,直到希望得到修复,请参阅gist.github.com/gurix/10c675632798da04d9d2。
标签: r warnings alpha suppress psych