Suppose I have a function such as:
ff <- function(x) { cat(x, \"\\n\") x^2}
And run it by:
y <- ff(5) # 5 y # [1
You can use capture.output with invisible
capture.output
invisible
> invisible(capture.output(y <- ff(2))) > y [1] 4
or sink
sink
> sink("file") > y <- ff(2) > sink() > y [1] 4