Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress output of stationarity test that is printed to screen

How do I get the stationarity test from the fractal package in R to not print any output to the screen.

For example, with the shapiro.wilk test when setting the result as a variable it does not give any output as follows

lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)

shap.p <- shapiro.test(lg.day.ret.vec)$p.value

This is the case for most tests but when I do it for the stationarity test I get some output in the r console.

library(fractal)

stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
1
2
3
4
5
6
N = 2609, nblock = 11, n_block_max = 238, dt =     1.0000
7
8
9
10
11
12
13
14
15
16
17
18
like image 517
Vik Avatar asked Feb 23 '15 00:02

Vik


1 Answers

In fact, you can suppress the output to R console by rerouting it. Two methods are available in R utils, sink, and capture.output. Both methods are intended to send output to a file.

Since you want to suppress the output of a single expression, you can use capture.output, with file=NULL (default). This will return your output as a string. To prevent showing this returned string in the R console, you can use invisible.

The final code can be:

library(fractal)

lg.day.ret.vec <- rnorm(100, mean = 5, sd = 3)
shap.p <- shapiro.test(lg.day.ret.vec)$p.value

invisible(capture.output(
    stat.p <- attr(stationarity(lg.day.ret.vec),"pvals")[1]
))

Hope this helps. Let me know if not.

like image 198
ahmohamed Avatar answered Oct 10 '22 22:10

ahmohamed