[R] Formatting summary() output to a file
William Dunlap
wdun|@p @end|ng |rom t|bco@com
Fri Jul 27 19:56:54 CEST 2018
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 Dunlap
TIBCO Software
wdunlap tibco.com
On Fri, Jul 27, 2018 at 8:52 AM, Rich Shepard <rshepard using appl-ecosys.com>
wrote:
> On Fri, 27 Jul 2018, William Dunlap wrote:
>
> Try
>> cat(sep="\n", file=con, capture.output(summary(...)))
>> capture.output(x) return character vector whose elements contain
>> the lines of text that would have been printed by print(x).
>>
>
> Bill,
>
> Thanks very much. I doubt my searches would have found capture.output().
>
>
> Rich
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list