Re: [R] Pretty printing progress

From: Doran, Harold <HDoran_at_air.org>
Date: Thu, 17 Jun 2010 12:15:42 -0400

I was actually trying to model some of what I'm doing after the verbose = TRUE argument in lmer, but had a hard time finding the chunk of code. I'm still looking for it, but got ahead of myself.

-----Original Message-----
From: dmbates_at_gmail.com [mailto:dmbates_at_gmail.com] On Behalf Of Douglas Bates Sent: Thursday, June 17, 2010 12:14 PM
To: Barry Rowlingson
Cc: Doran, Harold; r-help_at_r-project.org
Subject: Re: [R] Pretty printing progress

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:33:31 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