Pfaff, Bernhard
2004-Nov-22 10:33 UTC
[R] Rcmdr -> doItAndPrint -> summary method of S4-class object not in Rcmdr window but R Console
Dear list member, John Fox proposed to me posting this problem to R-Help: I have written a function suited for Rcmdr and included this in a R-file located in Rcmdr/etc as well as an augmented `Rcmdr-menus.txt'. Now, I am faced with the following problem: method show() of a S4-class object works flawlessly, that is `doItAndPrint' works flawlessly and its output is returned correctly into the Rcmdr-Window. However, by using method summary() for the same S4-class object fails, in the sense that the output is *not* printed in the Rcmdr window, but into the R Console. The summary()-method contains cat() and slots of the S4-class objects only. My question is: How can it be achieved that method summary() of S4 objects is printed in the RCmdr window and why, in the first instance, does it fail to do so by using `doItAndPrint'. Any help or pointer is much appreciated, Best Regards Bernhard platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 0.1 year 2004 month 11 day 15 language R -------------------------------------------------------------------------------- The information contained herein is confidential and is inte...{{dropped}}
Prof Brian Ripley
2004-Nov-22 10:56 UTC
[R] Rcmdr -> doItAndPrint -> summary method of S4-class object not in Rcmdr window but R Console
The FAQ Q8.1 does recommend that summary() methods do not print themselves but returned a classed object to be printed. What doItAndPrint does is to capture the result of an explicit print, so it will only work for summary methods that follow that recommendation. I do think doItAndPrint should be capturing all the output from a function via sink(), and not just the print of the final result. On Mon, 22 Nov 2004, Pfaff, Bernhard wrote:> Dear list member, > > John Fox proposed to me posting this problem to R-Help: > > I have written a function suited for Rcmdr and included this in a R-file > located in Rcmdr/etc as well as an augmented `Rcmdr-menus.txt'. > > Now, I am faced with the following problem: > method show() of a S4-class object works flawlessly, that is `doItAndPrint' > works flawlessly and its output is returned correctly into the Rcmdr-Window. > However, by using method summary() for the same S4-class object fails, in > the sense that the output is *not* printed in the Rcmdr window, but into the > R Console. The summary()-method contains cat() and slots of the S4-class > objects only. > > My question is: How can it be achieved that method summary() of S4 objects > is printed in the RCmdr window and why, in the first instance, does it fail > to do so by using `doItAndPrint'. > > Any help or pointer is much appreciated, > > Best Regards > Bernhard > > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 0.1 > year 2004 > month 11 > day 15 > language R > > > > > -------------------------------------------------------------------------------- > The information contained herein is confidential and is inte...{{dropped}} > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595