Re: [Rd] step() in sink() and Sweave()

2007-06-13 Thread Friedrich Leisch
 On Wed, 13 Jun 2007 16:43:32 +0300,
 Jari Oksanen (JO) wrote:

   On Wed, 2007-06-13 at 13:33 +0100, Gavin Simpson wrote:
   Dear Developers,
   
   This change also just bit me whilst updating Sweave documents for some
   computer classes.
   
   Is there a work-around that can be employed so that we get both the
   message() bits and the print() bits in the same place for our Sweave
   files?
   
   If not, is there any point in filing this as a bug in R? I see there
   have been no (public) responses to Jari's email, yet the change is
   rather annoying, and I do not see the rationale for printing different
   parts of the output from step() in two different ways.
   
   I think this is a bug. You should not use message() with optional trace.
   The template for the usage in step() is first

   if (trace) message()

   and later

   if (trace) print()

   If you specifically request printing setting  trace = TRUE, then you
   should not get message().

   Interestingly, message() seems to be a warning() that cannot be
   suppressed by setting options.

   This is so annoying that I haven't updated some of my Sweave documents.
   It is better to have outdated documents than crippled documents.

   You can handle this in sink(), but I don't know any trick for Sweave
   (and it's a nuisance in sink() as well).


The topic is on the agenda, but no released code yet. Hadley Wickham
has code collecting all output, messages, warning etc that arise when
an expression is evaluated which can be used in various places like
sink or Sweave to solve this problem. We have already scheduled
discussions for a workshop which we both attend in 3 weeks.

Sorry for not replying to the original email.

Best,
Fritz

-- 
---
Prof. Dr. Friedrich Leisch 

Institut für Statistik  Tel: (+49 89) 2180 3165
Ludwig-Maximilians-Universität  Fax: (+49 89) 2180 5308
Ludwigstraße 33
D-80539 München http://www.stat.uni-muenchen.de/~leisch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] step() in sink() and Sweave()

2007-06-13 Thread Seth Falcon
Jari Oksanen [EMAIL PROTECTED] writes:

 On Wed, 2007-06-13 at 13:33 +0100, Gavin Simpson wrote:
 Dear Developers,
 
 This change also just bit me whilst updating Sweave documents for some
 computer classes.
 
 Is there a work-around that can be employed so that we get both the
 message() bits and the print() bits in the same place for our Sweave
 files?
 
 If not, is there any point in filing this as a bug in R? I see there
 have been no (public) responses to Jari's email, yet the change is
 rather annoying, and I do not see the rationale for printing different
 parts of the output from step() in two different ways.
 
 I think this is a bug. You should not use message() with optional trace.
 The template for the usage in step() is first

 if (trace) message()

 and later

 if (trace) print()

 If you specifically request printing setting  trace = TRUE, then you
 should not get message().

 Interestingly, message() seems to be a warning() that cannot be
 suppressed by setting options.

message is a condition and so is a warning.  This means you have some
control over them.  For example, you can create a wrapper for step
that uses withCallingHandlers to cat out all messages (or print them,
or email them to your friends :-)

mystep - function(object, scope, scale = 0,
   direction = c(both, backward, forward),
   trace = 1, keep = NULL, steps = 1000, k = 2, 
   ...)
{
withCallingHandlers(step(object=object, scope=scope, scale=scale,
 direction=direction, trace=trace,
 keep=keep, steps=steps, k=k, ...),
message=function(m) {
cat(conditionMessage(m))
})
}

 This is so annoying that I haven't updated some of my Sweave documents.
 It is better to have outdated documents than crippled documents.

I'm not trying to argue that the function shouldn't change, but if it
is so annoying, you can also resolve this problem by defining your own
step function and calling it (forgetting about withCallingHandlers).
Clearly not ideal, but at the same time in the spirit of open source,
no?

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] step() in sink() and Sweave()

2007-06-13 Thread Gavin Simpson
On Wed, 2007-06-13 at 08:04 -0700, Seth Falcon wrote:
 Jari Oksanen [EMAIL PROTECTED] writes:
 
  On Wed, 2007-06-13 at 13:33 +0100, Gavin Simpson wrote:
  Dear Developers,
  
  This change also just bit me whilst updating Sweave documents for some
  computer classes.
  
  Is there a work-around that can be employed so that we get both the
  message() bits and the print() bits in the same place for our Sweave
  files?
  
  If not, is there any point in filing this as a bug in R? I see there
  have been no (public) responses to Jari's email, yet the change is
  rather annoying, and I do not see the rationale for printing different
  parts of the output from step() in two different ways.
  
  I think this is a bug. You should not use message() with optional trace.
  The template for the usage in step() is first
 
  if (trace) message()
 
  and later
 
  if (trace) print()
 
  If you specifically request printing setting  trace = TRUE, then you
  should not get message().
 
  Interestingly, message() seems to be a warning() that cannot be
  suppressed by setting options.
 
 message is a condition and so is a warning.  This means you have some
 control over them.  For example, you can create a wrapper for step
 that uses withCallingHandlers to cat out all messages (or print them,
 or email them to your friends :-)
 
 mystep - function(object, scope, scale = 0,
direction = c(both, backward, forward),
trace = 1, keep = NULL, steps = 1000, k = 2, 
...)
 {
 withCallingHandlers(step(object=object, scope=scope, scale=scale,
  direction=direction, trace=trace,
  keep=keep, steps=steps, k=k, ...),
 message=function(m) {
 cat(conditionMessage(m))
 })
 }
 
  This is so annoying that I haven't updated some of my Sweave documents.
  It is better to have outdated documents than crippled documents.
 
 I'm not trying to argue that the function shouldn't change, but if it
 is so annoying, you can also resolve this problem by defining your own
 step function and calling it (forgetting about withCallingHandlers).
 Clearly not ideal, but at the same time in the spirit of open source,
 no?

Thanks for the info on bypassing this issue Seth.

I disagree about your final comment though. If one is trying to teach
the use of step() to people in a computer practical class and you want
to show example output along with the commands used to produce it, you
can't do what you did and produce your own function - it wouldn't be a
good way to teach step() if I was using mystep() in the example code!

If this had been a report I was writing, I'd have just hacked my own
version of step that used print() all the time; one of the reasons I use
R in the first place is that I can go and do this. But this isn't an
option when teaching.

I am still a little mystified as to why the message() and print() bits
are used anyway. I mean, someone obviously felt this was a good idea or
they wouldn't have spent their time making the changes, and I accept
that I am probably not seeing the bigger picture here, but I don't see
the difference between the two bits of information and why you'd want to
treat them differently - why isn't the bit that is print()ed considered
a message for example?

Cheers,

G

 
 + seth
 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] step() in sink() and Sweave()

2007-05-09 Thread Jari Oksanen
Dear developers,

I just noticed that step() function currently prints the current model
using message(), but the resulting model using print(). The relevant
commands within the step() body are:

if (trace) message(Start:  AIC=, format(round(bAIC, 2)), \n, 
cut.string(deparse(as.vector(formula(fit, \n)

(with example() output:) 
Start:  AIC=190.69
Fertility ~ Agriculture + Examination + Education + Catholic + 
Infant.Mortality

And later:

if (trace) print(aod[o, ])

(with example() output:)

   Df Sum of SqRSSAIC
- Examination   1  53.0 2158.1  189.9
none  2105.0  190.7
- Agriculture   1 307.7 2412.8  195.1
- Infant.Mortality  1 408.8 2513.8  197.0
- Catholic  1 447.7 2552.8  197.8
- Education 11162.6 3267.6  209.4

This is a nuisance if you want to divert output to a file with sink() or
use step() in Sweave: the header and the table go to different places,
and without message() part the print() part is crippled.  It may be that
there is some way to avoid this, but obviously that needs some degree of
acrobatic R skills. 

An example of the behaviour:

sink(tempfile())
example(step)
sink()

I assueme that the behaviour is intentional but searching NEWS did not
give any information or reasoning. Would it be sensible to go back to
the old behaviour? I found some Swoven files from R 2.4.0 that still put
both parts of the output to the same place. For the sake of Sweave and
sink, I'd prefer the one place to be stdout instead of stderr.

Best wishes, Jari Oksanen
-- 
Jari Oksanen [EMAIL PROTECTED]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel