sink(file=<<see below>>, command=<<see below>>, append = F, on.exit = expression(), unsink.to) sink.number()
sink.number returns the number of sinks in effect.
If both file and command are omitted, a diversion is ended.
Sink files can be nested, i.e., if sink is called when output is being diverted to a sink file, the previous diversion is suspended and then resumed when the nested sink is terminated by calling sink() with no arguments.
To produce a file with both the input and the output, use the UNIX command script, if available. Such a script file may need editing to remove control characters.
sink("stem.dat") # divert output to file stem(data) sink() # revert output to the terminal !lpr stem.dat # To write a function that puts some output into a file and make # sure the sink is closed, even if there is an error in the function, # use on.exit as follows f <- function(file) { old.sink.level <- sink(file) on.exit(sink(unsink.to=old.sink.level)) print(lm(Price~Supply)) }