How to hide or disable in-function printed message

Solution 1:

You can use capture.output with invisible

> invisible(capture.output(y <- ff(2)))
> y
[1] 4

or sink

> sink("file")
> y <- ff(2)
> sink()
> y
[1] 4

Solution 2:

Here's a nice function for suppressing output from cat() by Hadley Wickham:

quiet <- function(x) { 
  sink(tempfile()) 
  on.exit(sink()) 
  invisible(force(x)) 
} 

Use it like this:

y <- quiet(ff(5))

Source: http://r.789695.n4.nabble.com/Suppressing-output-e-g-from-cat-td859876.html