[R] Formatting summary() output to a file

Rich Shepard r@hep@rd @end|ng |rom @pp|-eco@y@@com
Fri Jul 27 20:19:36 CEST 2018


On Fri, 27 Jul 2018, William Dunlap wrote:

> I often use capture.output to slightly reformat printout output.  E.g, to
> indent str's output to make it easier to read debugging printouts:
> debug_print <- function(x, name=substitute(x), indent=4)
> {
>   cat(sep="\n", name, paste0(strrep(" ", indent), capture.output(str(x))))
> }
> Used as in
>> myData <- list(One=1:100,Two=log2(1:5))
>> debug_print(myData)
> myData
>    List of 2
>     $ One: int [1:100] 1 2 3 4 5 6 7 8 9 10 ...
>     $ Two: num [1:5] 0 1 1.58 2 2.32

Bill,

   This is good to know.

Many thanks,

Rich




More information about the R-help mailing list