Program : R 3.2.1 for Mac OSX
IDE : RStudio
Output : rmkd > html
Package : "psych"
Function : alpha()
Problem :
While using alpha(data, na.rm=F, check.keys=F, delete=F), because portions of the input-data is negatively correlated and because I have check.keys = FALSE, I get the following message :
Some items XXX 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
Question :
My check.keys is set intentionally. Fully understanding the implications of the warning & mostly for aesthetic and educational reasons, how can I suppress it in my output?
Attempts so far :
1. I've tried suppressWarnings() & suppressMessages().
2. I've tried invisible() & sink(., type="message").
3. In the Rmd block, I've tried : ```{r warning=F, message=F}
4. Exploring print(alpha) I found what I think is the origin. Maybe someone understands how to suppress this part of the code? :
`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")
}
}`
thanks!
The culprit here is cat, which will not heed suppressMessages etc.
To catch it, you can use capture.output instead:
invisible(capture.output(alpha(data, na.rm=F, check.keys=F, delete=F)))
capture.output calls sink(…, type = "output") internally and discards/returns the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With