Albrecht, Dr. Stefan (AZ Private Equity Partner)
2007-Apr-12 14:08 UTC
[R] Method dispatch for print() in package its
Dear all, in the package its the print() method does not seem to correctly work in all circumstances:> selectMethod(print, "its")Method Definition: function (x, ...) { print(x@.Data <mailto:x@.Data> , ...) } <environment: namespace:its> Signatures: x target "its" defined "its"> fundPME.lst[[1]]$irrAn object of class "its" IRR HSBC MEEM 2005-10-31 0.1926175 0.07802736 Slot "dates": [1] "2005-10-31 Westeuropäische Normalzeit"> fundPME.lst[[1]]$irr@.DataIRR HSBC MEEM 2005-10-31 0.1926175 0.07802736> print(fundPME.lst[[1]]$irr)IRR HSBC MEEM 2005-10-31 0.1926175 0.07802736 So, is it necessary to define a print.its S3 method, or what should we do? Many thanks and best regards, Stefan ____________________________________ Dr. Stefan Albrecht, CFA Allianz Private Equity Partners GmbH Königinstr. 19 | 80539 Munich | Germany Phone: +49.(0)89.3800.18317 Fax: +49.(0)89.3800.818317 EMail: stefan.albrecht@allianz.com <mailto:stefan.albrecht@allianz.com> Web: www.apep.com <http://www.apep.com/> Allianz Private Equity Partners GmbH | Geschäftsführung: Wan Ching Ang, Karl Ralf Jung Sitz der Gesellschaft: München | Registergericht: München HRB 126221 | Ust-ID-Nr.: DE 813 264 786 [[alternative HTML version deleted]]
Without a reproducible example I can't tell what the problem is but as a workaround you could print it as a zoo object: library(its) library(zoo) # create an its object example(its) ii <- its(mat, times) # print it without using its' print print(as.zoo(ii)) # or from the command line just as.zoo(ii) On 4/12/07, Albrecht, Dr. Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com> wrote:> Dear all, > > in the package its the print() method does not seem to correctly work in all circumstances: > > > > selectMethod(print, "its") > Method Definition: > > function (x, ...) > { > print(x at .Data <mailto:x at .Data> , ...) > } > <environment: namespace:its> > > Signatures: > x > target "its" > defined "its" > > > > > fundPME.lst[[1]]$irr > An object of class "its" > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > Slot "dates": > [1] "2005-10-31 Westeurop?ische Normalzeit" > > > > fundPME.lst[[1]]$irr at .Data > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > > > > print(fundPME.lst[[1]]$irr) > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > > > So, is it necessary to define a print.its S3 method, or what should we do? > > Many thanks and best regards, > Stefan > > ____________________________________ > Dr. Stefan Albrecht, CFA > Allianz Private Equity Partners GmbH > K?niginstr. 19 | 80539 Munich | Germany > > Phone: +49.(0)89.3800.18317 > Fax: +49.(0)89.3800.818317 > EMail: stefan.albrecht at allianz.com <mailto:stefan.albrecht at allianz.com> > Web: www.apep.com <http://www.apep.com/> > > > Allianz Private Equity Partners GmbH | Gesch?ftsf?hrung: Wan Ching Ang, Karl Ralf Jung > Sitz der Gesellschaft: M?nchen | Registergericht: M?nchen HRB 126221 | Ust-ID-Nr.: DE 813 264 786 > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. > >
"Albrecht, Dr. Stefan (AZ Private Equity Partner)" <stefan.albrecht at apep.com> writes:> Dear all, > > in the package its the print() method does not seem to correctly > work in all circumstances:My understanding is that one should define only a method for the show generic for S4 classes and leave print alone. Not sure if that helps you. + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
Setting S4 methods for print() works correctly, as in your examples. Your first example does not call print(), so it is not suprising that no method dispatch takes place. You seem to suppose that such a method should be used for top-level auto-printing, and it will not be as your example shows. Auto-printing calls show() on S4 objects, and in this case show() is handling the object by its default method. Note that if there is no S4 print method set, print(x) on an S4 object 'x' will in fact call show(x). So had an S4 show() method been set, all three examples would have given the same output (via show()). On Thu, 12 Apr 2007, Albrecht, Dr. Stefan (AZ Private Equity Partner) wrote:> Dear all, > > in the package its the print() method does not seem to correctly work in all circumstances: > > >> selectMethod(print, "its") > Method Definition: > > function (x, ...) > { > print(x at .Data <mailto:x at .Data> , ...)(sic!)> } > <environment: namespace:its> > > Signatures: > x > target "its" > defined "its" > > > >> fundPME.lst[[1]]$irr > An object of class "its" > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > Slot "dates": > [1] "2005-10-31 Westeurop?ische Normalzeit" > > >> fundPME.lst[[1]]$irr at .Data > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > > >> print(fundPME.lst[[1]]$irr) > IRR HSBC MEEM > 2005-10-31 0.1926175 0.07802736 > > > So, is it necessary to define a print.its S3 method, or what should we do? > > Many thanks and best regards, > Stefan > > ____________________________________ > Dr. Stefan Albrecht, CFA > Allianz Private Equity Partners GmbH > K?niginstr. 19 | 80539 Munich | Germany > > Phone: +49.(0)89.3800.18317 > Fax: +49.(0)89.3800.818317 > EMail: stefan.albrecht at allianz.com <mailto:stefan.albrecht at allianz.com> > Web: www.apep.com <http://www.apep.com/> > > > Allianz Private Equity Partners GmbH | Gesch?ftsf?hrung: Wan Ching Ang, Karl Ralf Jung > Sitz der Gesellschaft: M?nchen | Registergericht: M?nchen HRB 126221 | Ust-ID-Nr.: DE 813 264 786 > > > > [[alternative HTML version deleted]] > >-- 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