Disabling the cat command
Here is a funny hack that comments out all the cat()
's in a function. Not sure if this gives errors or breaks the function though:
foo <- deparse(f)
f <- eval(parse(text=gsub("cat","#cat",foo)))
f()
[1] 1
Edit:
Another option is basically Juba's answer, using sink, but you can use the Defaults
package to change the default behavior of cat
. The file
argument basically sinks its output in a file. So :
library("Defaults")
setDefaults(cat,file="sink.txt")
f()
Ensures that only output of cat
and not print
or so is sinked. However, this drastically reduces the runtime since now a file is opened and closed everytime cat()
is run.
This should work?
oldcat = cat
cat = function( ..., file="", sep=" ", fill=F, labels=NULL, append=F ) {}
f()
cat = oldcat
Just replace cat
with an empty function
, and then set it back on completion
On Linux, you can use a sink()
call to /dev/null
(or to a temporary file on another OS, see ?tempfile
) :
sink(file="/dev/null")
f()
sink()