Re: [R] Pretty printing progress

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Thu, 17 Jun 2010 11:13:52 -0500

On Thu, Jun 17, 2010 at 10:50 AM, Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk> wrote:
> On Thu, Jun 17, 2010 at 3:33 PM, Doran, Harold <HDoran@air.org> wrote:
>> I have a function that is an iterative process for estimating some MLEs. I want to print some progress to screen as the process iterates. I would like to try and line things up nicely in the R window, but am not sure the best way to do this. Below is a toy example. Suppose I want the value of 10 to be just below "iteration" and the value of -1234 to be just below 'Log Likelihood'.
>
>  Sure you just dont want to use the progress bar functions from the
> plyr package:
>
> ?plyr::create_progress_bar
>
>  another example of things being in the wrong package....

If you want to stick with a text display you can use the sprintf function to format the strings that you print

> cat('Iteration Log Likelihood\n', sprintf("%8d%20g\n", 10, -1234))

Iteration      Log Likelihood
       10               -1234

I would avoid the tab character as you can't count on the displays of tabs to be consistent. You may also want to change the display of the log-likelihood to be a fixed number of decimal places rather than a general format for floating point numbers, which can switch into the "e" notation for very large or very small numbers.

> cat('Iteration Log Likelihood\n', sprintf("%8d%20.4f\n", 10, -1234))

Iteration      Log Likelihood
       10          -1234.0000

The format of the format strings is another "little language" to learn but it is a very powerful mechanism.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 17 Jun 2010 - 16:19:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jun 2010 - 16:40:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive