From deepayan.sarkar at gmail.com  Thu Jan  5 06:01:13 2006
From: deepayan.sarkar at gmail.com (Deepayan Sarkar)
Date: Wed, 4 Jan 2006 23:01:13 -0600
Subject: [Rd] defining a print method
In-Reply-To: <971536df0601042047p24519c59nce098ab8e134b4e2@mail.gmail.com>
References: <971536df0601042047p24519c59nce098ab8e134b4e2@mail.gmail.com>
Message-ID: <eb555e660601042101n5b90dd99i278fc67a8b0752f5@mail.gmail.com>

On 1/4/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> In the following session we define an xx class and a print method
> for it.  If I invoke it with print then it prints as expected but if
> we just type xx at the R prompt then we get nothing back.  How
> do we define the print method so that it works in the latter
> case too?
>
> > xx <- structure("abc", class = "xx")
> > print.xx <- function(x, ...) shQuote(x)

shQuote doesn't print anything, you probably want

print.xx <- function(x, ...) print(shQuote(x))

-Deepayan

> > print(xx) # ok
> [1] "\"abc\""
> > xx # no output ????
> >
> > sessionInfo()
> R version 2.2.1, 2005-12-20, i386-pc-mingw32
>
> attached base packages:
> [1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
> [7] "base"



[Rd] defining a print method
Deepayan Sarkar