I'm using RCaller
to execute some analysis on a data frame within my Java application
. More specifically, I want to run Coarsened Exact Matching
using the CEM
library of R
.
As far as CEM
is concerned, it returns some data about the mathching, if any match is found. Otherwise (no match found) it fails.
When I call the runAndReturnResult
method from my Java application
, if CEM
fails inside R
, RCaller
automatically prints on my Java application's console
, all the code that I added to my RCode
instance.
Is there a way for preventing this printing? I mean, I want to ignore the cases in which no match is found and move forward, without printing messages on my console.
Thanks in advance to anyone that can help.
There are two ways to handle this:
RCaller
is using java.util.logging.Logger
, so you need to add a logback.xml - file
for disabling the output of the logger
.tryCatch({})
inside R
so that your R code
won't break -> won't trigger any errors in Java
.I would recommend the second solution.
update:
you have to add an error - block
mat <- tryCatch({
cem(treatment = "c_CLUSTER", data = df, drop = dp))
}, error = function(e) {
NULL # or do something else
}, finally = {
})
And if you want to ignore all the warnings
, wrape your method call
in suppressWarnings(<method-call>)
Or you can also add an warning - block
to the tryCatch - block