In R, is it possible to redirect console output to a variable? -
in r, i'm wondering if it's possible temporarily redirect output of console variable?
p.s. there few examples on web on how use sink() redirect output filename, none find showing how redirect variable.
p.p.s. reason useful, in practice, need print out portion of default console output of built in functions in r.
i believe results <- capture.output(...) need (i.e. using default file=null argument). sink(textconnection("results")); ...; sink() should work well, ?capture.output says, capture.output() is:
related ‘sink’ in same way ‘with’ related ‘attach’.
... suggests capture.output() better since more contained (i.e. don't have remember terminate sink()).
if want send output of multiple statements variable can wrap them in curly brackets {}, if block sufficiently complex might better use sink() (or make code more modular wrapping in functions).
Comments
Post a Comment