In R some functions can print information and return values, can the print be silenced?
For example:
print.and.return <- function() {
print(\"foo\
I agree with hadley and mbq's suggestion of capture.output
as the most general solution. For the special case of functions that you write (i.e., ones where you control the content), use message
rather than print
. That way you can suppress the output with suppressMessages
.
print.and.return2 <- function() {
message("foo")
return("bar")
}
# Compare:
print.and.return2()
suppressMessages(print.and.return2())