I am writing an R-package with some C++ code running lengthy calculations. Inside the C++ code, I am using Rprintf() to output information. I tried suppressing the output from R with suppressMessages(), but this doesn't work, the messages still appear inside the R session.
I found some similar questions, where people were using printf instead of Rprintf, but I am already using Rprintf. I also tried R_ShowMessage(), which is also immediately displayed and not suppressed by suppressMessages().
Here is some example C++ code:
#include <R.h>
extern "C" {
void R_testprint()
{
Rprintf("Try to suppress me!\n");
R_ShowMessage("Try to suppress me, too!");
}
}
And the function that calls this code:
test.print <- function(string) {
res <- .C("R_testprint")
}
Now, the following R code will not suppress the output:
> suppressMessages( test.print() )
Try to suppress me!
Try to suppress me, too!
I am using R version 3.1.0
I appreciate any help!
Use capture.output
in place of suppressMessages
:
b <- capture.output( test.print() )
Then the output is stored in character vector b
instead of being printed.
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