libstableR library unwanted output - r

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.

Related

How to suppress not traditional warnings in R Console for Shiny

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!!

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.

Automatic Plotting in *.r file

I do have a *.r file where I order it to coduct a Chi Square of Independence and write it to an html file. It's working fine but I'd like to add a graph.
Doing by hand in R with linecommands works perfectly, but the exact same commands do not work in the *.r file but i want it to do it automatically.
mat1 <-matrix(c(12,3,2,12),nrow=2,byrow=T)
attach(mat1)
png('independence.png')
barplot(mat1,beside=TRUE)
dev.off()
Is there an additional command necessary?
kind regards
If you have an error in a script with no try or tryCatch, then entrie script fails. By trying to attach a matrix, you throw an error with the message:
Error in attach(mat1) :
'attach' only works for lists, data frames and environments
So you should pay more attention to the error messages in interactive mode, and if you are planning to use .r files for production you should learn to use error handling routines in R. The `attach function is a common source of new user errors, although this error is not particularly common. The more common errors with its use involve regression functions where the authors of the functions are expecting entire objects, usually dataframes, to be passed to a data argument.

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")

Trapping R Errors in rpy2

When I use RStudio, I can see any errors or warnings when I run a function.
However when I am using, rpy2, how can I catch warnings (which allow the code to run) and errors (which stall the code) so I can parse the messages programmatically in python?
Until R-3.0 (current unreleased), warnings were printed to the console by default.
From R-3-0, they are no longer printed because the R developers made the C function previously used hidden (and are too busy to document why and tell whether we could get access to that function back or not).
To get the warnings as an rpy2 object, you can do:
from rpy2.robjects.packages import importr
base = importr('base')
# do things that generate R warnings
base.warnings()
Errors occurring while evaluating R code raise an rpy2.rinterface.RRuntimeError. Just catch those.

Resources