Suppress one command's output in R

468    Asked by Unnatigautam in Data Science , Asked on Jun 8, 2021

I'm looking to suppress the output of one command (in this case, the apply function).

Is it possible to do this without using sink()? I've found the described solution below but would like to do this in one line if possible. How R suppress output?

Answered by Julie Baber

To suppress the output of any command, apart from the sink() function, you can use the invisible() function as follows:

apply(matrix(1:10), 1, as.numeric)
 [1] 1 2 3 4 5 6 7 8 9 10
invisible(apply(matrix(1:10), 1, as.numeric))
>

This way you can surpass output in R.



Your Answer

Interviews

Parent Categories