How to suppress not traditional warnings in R Console for Shiny - r

I have an R Shiny app. And I am making predictions from 10k xgboost models in the app. And the R console will show such error each time I make a prediction from a single model:
[23:13:24] WARNING: amalgamation/../src/objective/regression_obj.cu:152: reg:linear is now deprecated in favor of reg:squarederror.
Some explanations about this warning can be found here: https://github.com/dmlc/xgboost/issues/4599
(I don't have time and can't rerun these models to fix the warnings now.)
Also, notice this is not a normal warning from the Shiny because this error is in black color and also showing in the specific form (see above).
I tried to use suppressWarnings function on my predict and other method such as the first reply in this thread: Suppress warning message in R console of shiny
But I still have the warnings. I think there are 10k warnings and my result will be shown on the Shiny interface after all the warnings are loaded, which is a big slow-down.
So anyone knows how to solve this? Or even a global way, such as suppress any output in R console while running a Shiny app.
Thanks in advance!!

Related

Cannot not find "calc.RL.0" function within "mixstock" package

I am trying to run through a mixed stock analysis in RStudio based on the walkthrough provided by Bolker (https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=043730a02b148396ebd54b2f62e8f6364714b1b2), using the 'mixstock' package and the example 'lahanas98raw' dataset within. However, I am receiving a warning that the 'calc.RL.0' function cannot be found whilst trying to carry out Raftery and Lewis convergence diagnostics (p.14 of Bolker's walkthrough). I am wondering whether one of the packages has not installed properly (i.e., either 'mixstock' or 'coda'), or whether there is another package I can use to run this diagnostic instead.
When I initially tried to install the 'mixstock' package, the following warning came up:
'Warning in install.packages : package ‘mixstock’ is not available for this version of R.'
I tried installing the version of R (2.14.1) described as the 'current version of R' on page 2 of Bolker's walkthrough, but when I then tried to switch to this version of R in RStudio via the options menu, it says that this version of R is not compatible with RStudio. To work around this, I downloaded the 'mixstock' package (version 0.9.5.1) from the CRAN archive (https://cran.r-project.org/src/contrib/Archive/mixstock/) and uploaded it to RStudio this way instead.
This seemed to have worked, as I successfully ran through a significant amount of the code, but a new error arose when I tried to run Raftery and Lewis convergence diagnostics (p.14). When I try to run calc.RL.0(mydata), I receive the following error:
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
However, when I click on 'mixstock' in the package window, everything seems fine and the 'calc.RL.0' function appears, alongside several other 'calc' functions (e.g. 'calc.GR', 'calc.mult.GR', 'calc.mult.RL') that can all be found and run fine. The 'calc.RL.0' function relies on the 'raftery.diag' function within the 'coda' package, so I have also made sure that is installed and called. I have tried a bunch of other methods but nothing seems to be working.
Here is some of my code leading up to the warning message:
## Calculate confidence intervals - i.e., bootstrapping - and plot them
mydata.umlboot = genboot(mydata,"uml")
confint(mydata.umlboot)
plot(mydata.umlboot, ylim=c(0,1))
## Carry out Markov Chain Monte Carlo (MCMC) estimations and plot them
mydata.mcmc = tmcmc(mydata)
mydata.mcmc
confint(mydata.mcmc)
plot(mydata.mcmc, ylim=c(0,1))
## Check that the Markov chains have converged = run Raftery and Lewis diagnostics
library(mixstock)
library(coda)
calc.RL.0(mydata)
'Error in calc.RL.0(mydata) : could not find function "calc.RL.0"'
Could this be something to do with the way the 'mixstock' package was initially installed, or is it likely to be another issue? Is there another way to run Raftery and Lewis diagnostics and still get the outputs I need (diagnostics for the last chain evaluated; the history of how long each suggested chain was)? Any help would be much appreciated - thanks in advance!
The most reliable way to install mixstock, if you have development tools installed on your computer (compilers etc.), is remotes::install_github("bbolker/mixstock") (I don't think I've changed anything/fixed any bugs since the archived version, but if I did the changes would be reflected on GitHub.)
It looks like I forgot to export that function, so
mixstock:::calc.RL.0(mydata)
should work (this is something I can/should fix). Note that the Gelman-Rubin diagnostic (calc.GR(), which is properly exported) is more reliable than Raftery-Lewis anyway ...

libstableR library unwanted output

I'm using libstableR library to calculate some estimators and function stable_fit_mle outputs some messages while running, namely tons of Minimizer warning: No error and occasionally also: FINAL ESTIMATED PARAMETER ARE NOT VALID: No error.
I managed to suppress those messages in my final document (compiled with R Sweave) with invisible(capture.output(...)) but those still clutter my console during compilation. Is there any way to stop those messages from appearing in the first place?
My main concern is to understand why stable_fit_mle is outputing these warnings (in oppose to similrar functions from libstableR package) and how to prevent this behaviour.

How to address explicit widget id warning for a shiny app using metricsgraphics?

I've built a shiny application that uses metricsgraphics to create histogram. When running the application I get the following error message:
Warning in output$histPlot(...) :
Ignoring explicitly provided widget ID "mjs-acd1c2bc860bf1a81780a7603d6f7b"; Shiny doesn't use them
The only place I've seen this warning discussed is on the issues page for metricsgraphics but no solution is provided. My app can be run with the following command:
shiny::runGitHub(repo = 'mihiriyer/mental')
My code is located here: https://github.com/mihiriyer/mental/blob/master/app.R
The app seems to work fine and so should even be worried since it is just a warning? Should I just suppress the message and move on?
Apparently not much can be done other than suppressing the warning message. Posted my question on Github, the response I got is here:
https://github.com/hrbrmstr/metricsgraphics/issues/49
Basically, one can add the following line to the server function section and the warnings will be suppressed:
options(warn = -1)

Convergence warnings missing from knit documents if fits wrapped in summary()

I use knitr/rmarkdown to document my analyses for others and myself.
The package I use, lme4, produces convergence warnings, which need to be documented.
If I run my model in the console, I get the warning right after, but the same warnings do not show inside the knit document, they end up in the Markdown console (i.e. after knitting is over).
It somehow depends on the top-level function that is being executed. To reproduce this, I tried creating a warning inside a function myself. This always showed in the Markdown.
While writing the question, it occured to me that I might play with options(warn). Setting it to 1 makes the warnings occur immediately in the Markdown console, but not in the knit document itself.
This at least fixes this problem: if I get too many warnings, I'm asked to execute warnings() but can't do so in the knitting parent environment.
Here's a reproducible script:
http://rpubs.com/rubenarslan/missing_convergence_warnings
I've figured out that the convergence warnings are only hidden if I wrap the model fitting into summary like so summary(m1 <- glmer(...)), not if I do m1 <- glmer(...); summary(m1). I borrowed the example and also found a way to get convergence warnings from the fit using this extractor fit#optinfo$conv$lme4$messages.
I can change my scripts now, but I don't really think it should be this way, I don't see a real difference between the two approaches, wrapping in summary is just more concise, the top-level function is knit in both cases.

Where can I find a log of R session warnings?

One of my R scripts produced a message that there are some warnings during processing. However, since this is not an interactive session, I can't use warnings() to access the warnings. What is the standard location, if any, of the most recent R session's warnings log file, so that I could review them? Thank you!
From ?warnings:
It is undocumented where last.warning is stored nor that it is
visible, and this is subject to change.
However, you can use the function warnings in your script and specify a file, where the last warnings should be saved.
warnings(file = "C:/Rwarnings.txt")

Resources