From |uke-t|erney @end|ng |rom u|ow@@edu  Wed May 22 18:03:00 2019
From: |uke-t|erney @end|ng |rom u|ow@@edu (Tierney, Luke)
Date: Wed, 22 May 2019 16:03:00 +0000
Subject: [Rd] [External] Re: print.<strorageMode>() not called when
 autoprinting
In-Reply-To: <411491BA-CE6C-4289-954B-EF3D31670669@rstudio.com>
References: <CAF8bMcatAtZ_LPWZk3QxVQXS5qHA14_j=_tBvGbbH+m0kBYnAQ@mail.gmail.com>
 <23780.10058.726995.538115@stat.math.ethz.ch>
 <CAF8bMcYeVioX6-vxz+-P6SsFHyoU6QSBD55_veNcvXpw7wEdyA@mail.gmail.com>
 <76885C3C-1100-490B-990E-5519F6AAD40B@rstudio.com>
 <CAF8bMcYX5o2joaqXa2F2Tw8iU-CvN8FmmGm58Yezs-RnwWxEGQ@mail.gmail.com>
 <23780.65330.841197.95483@stat.math.ethz.ch>
 <411491BA-CE6C-4289-954B-EF3D31670669@rstudio.com>
Message-ID: <alpine.DEB.2.21.1905221051470.2805@luke-Latitude-7480>

On Wed, 22 May 2019, Lionel Henry wrote:

> Hi Martin,
>
>> On 22 May 2019, at 03:50, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>>
>> I'm pretty sure that all teaching and documentation about S and R
>> has suggested that  print(f)  and auto-printing should result in
>> the same output _ AFAIR also for S4 objects

Looks like we intend auto-printing to do what evaluating the expression

    if (base::isS4(base::.Last.value)) methods::show(base::.Last.value) else base::print(base::.lastValue)

would do. The simplest approach would be to save this expression and
pass it to eval, or define an equivalent .autoprint function. That
would avoid code duplication and divergence.

I'm guessing the main reason we don't do this is that going through
the print() closure bumps NAMED on the value and forces a duplicate on
a subsequent assignment. This issue would disappear if we could manage
the transition to reference counting. In the meantime it would seem
best to keep any changes consistent with evaluating this expression.

Best,

luke

>
> I agree with the principle that autoprint and print() should be
> equivalent for users. However it also seems that print calls in
> packages should be independent of user customisations. For instance a
> package author might gather tabular data in a matrix or data frame and
> print() it as part of a larger print method. In that case, user
> customisations might cause a mess.
>
> Would it make sense to resort to autoprint customisation when the
> topenv() of the parent.frame() of print() is the global environment,
> and ignore the customisation otherwise? This should ensure consistent
> printing behaviour at the REPL and in scripts. Checking the topenv()
> allows print() calls inserted to debug lapply'd functions to behave the
> same as when called from top level or within a loop.
>
> Lionel
>
> ______________________________________________
> 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] [External] Re: print.<strorageMode>() not called when autoprinting
Tierney, Luke