From luke-tierney at uiowa.edu  Mon Jul 20 22:29:25 2015
From: luke-tierney at uiowa.edu (luke-tierney at uiowa.edu)
Date: Mon, 20 Jul 2015 15:29:25 -0500
Subject: [Rd] Defining a `show` function breaks the print-ing of S4
 object -- bug or expected?
In-Reply-To: <5592F8D7.5020200@gmail.com>
References: <CA+j8Z+=233OjOe00qV+5MdF9kkkVrWh4wfmUeAzwb4Q12DSxew@mail.gmail.com>
	<CABdHhvEVbdbNKUswtqENgfy1L4yQDOEEKyO--ft+x7f2M+ALPg@mail.gmail.com>
	<5592898B.5000103@gmail.com>
	<CABdHhvG7XJS6td4CxYYPBjgtwXqShGcRuDHvJ=HaKPT7jdb6VA@mail.gmail.com>
	<alpine.OSX.2.02.1506301009280.7711@lukes-macbook-air.local>
	<CALxY2LfF-vP5GdN174sy_V-290VVeUJUWVBUVriepGg2qzCKcw@mail.gmail.com>
	<5592B6E0.30009@gmail.com> <5592CC34.20309@gmail.com>
	<5592F8D7.5020200@gmail.com>
Message-ID: <alpine.DEB.2.10.1507201527470.2488@luke-Latitude>

This fixed in R-devel in r68702; in R-3-2-branch in r68705.

Best,

luke

On Tue, 30 Jun 2015, Duncan Murdoch wrote:

> On 30/06/2015 7:04 PM, Paul Gilbert wrote:
>>
>>
>> On 06/30/2015 11:33 AM, Duncan Murdoch wrote:
>>> On 30/06/2015 5:27 PM, Lorenz, David wrote:
>>>> There is something I'm really missing here. The function show is a
>>>> standardGeneric function, so the correct way to write it as method like
>>>> this:
>>>
>>> That describes methods::show.  The problem is that the default print
>>> mechanism isn't calling methods::show() (or base::print() as Luke says),
>>> it's calling show() or print() in the global environment, so the user's
>>> function overrides the generic, and you get the error.
>>
>> These are two different problems aren't they? I can see that you might
>> want to ensure that base::print() calls methods::show(), but forcing the
>> default print to go to base::print(), rather than whatever print() is
>> first on the search path, would seem like a real change of philosophy.
>> What about all the other base functions that can be overridden by
>> something in the global environment?
>
> I'd guess it's a minority of R users who know that print() or show() is
> being called when you just evaluate an expression.  Most would think R
> just shows you the value of the expression.  That's why they'd be
> surprised when their local function suddenly stops the display of
> variables from working.
>
> On the other hand, if someone defined a print or show *method* in the
> global environment, I think that one should override one defined in a
> package namespace.  It does now, and I wouldn't change that.  The
> difference is that I'd expect someone defining a method to know what
> they're doing, but just defining a function doesn't imply that.
>
> Duncan Murdoch
>
>>
>> Paul
>>>
>>> Luke, are you going to look at this, or should I?
>>>
>>> Duncan Murdoch
>>>
>>>>
>>>> setMethod("show",  "Person", function(object) {
>>>>
>>>> for an object of class "Person" for example.
>>>
>>>
>>>> Dave
>>>>
>>>> On Tue, Jun 30, 2015 at 10:11 AM, <luke-tierney at uiowa.edu> wrote:
>>>>
>>>>> Same thing happens with S3 if you redefine print(). I thought that
>>>>> code was actually calculating the function to call rather than the
>>>>> symbol to use, but apparently not. Shouldn't be too hard to fix.
>>>>>
>>>>> luke
>>>>>
>>>>> On Tue, 30 Jun 2015, Hadley Wickham wrote:
>>>>>
>>>>>   On Tue, Jun 30, 2015 at 2:20 PM, Duncan Murdoch
>>>>>> <murdoch.duncan at gmail.com> wrote:
>>>>>>
>>>>>>> On 30/06/2015 1:57 PM, Hadley Wickham wrote:
>>>>>>>
>>>>>>>> A slightly simpler formulation of the problem is:
>>>>>>>>
>>>>>>>> show <- function(...) stop("My show!")
>>>>>>>> methods::setClass("Person", slots = list(name = "character"))
>>>>>>>> methods::new("Person", name = "Tom")
>>>>>>>> #> Error in (function (...)  : My show!
>>>>>>>>
>>>>>>>
>>>>>>> Just to be clear:  the complaint is that the auto-called show() is not
>>>>>>> methods::show?  I.e. after
>>>>>>>
>>>>>>> x <- methods::new("Person", name = "Tom")
>>>>>>>
>>>>>>> you would expect
>>>>>>>
>>>>>>> show(x)
>>>>>>>
>>>>>>> to give the error, but not
>>>>>>>
>>>>>>> x
>>>>>>>
>>>>>>> ??
>>>>>>>
>>>>>>
>>>>>> Correct - I'd expect print() to always call methods::show(), not
>>>>>> whatever show() is first on the search path.
>>>>>>
>>>>>> Hadley
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> Luke Tierney
>>>>> Ralph E. Wareham Professor of Mathematical Sciences
>>>>> University of Iowa                  Phone:             319-335-3386
>>>>> Department of Statistics and        Fax:               319-335-3017
>>>>>     Actuarial Science
>>>>> 241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
>>>>> Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu
>>>>>
>>>>>
>>>>> ______________________________________________
>>>>> R-devel at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>
>>>> 	[[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu



[Rd] Defining a `show` function breaks the print-ing of S4 object -- bug or expected?
luke-tierney at uiowa.edu