Message-ID: <002601d336bf$242a9420$6c7fbc60$@uke.de>
Date: 2017-09-26T12:01:09Z
From: Daniel Lüdecke
Subject: [R-pkg-devel] tibbles are not data frames
In-Reply-To: <CABtg=Km5WRHGP0Ze0G6Og7AgwErJWudp8_ODq=barjJzFj=vbw@mail.gmail.com>
You wrote:
The correct and logical way (which I use in 'eha') is to check if input is a data frame, and if not, throw an error.
If you want to check for a data frame (and a data frame only), because you don't want to coerce *any* object to data frames, then this would be one way to check for df/tibble, and coerce tibbles only. That's what I had in mind...
But as I mentioned before, since simplifying is the most (or even only?) relevant point when dealing with tibbles, I have re-written all parts in my packages that used df[, x] indexing, and replaced with df[[x]], resp. used df[, x, drop = FALSE], or - if a vector is needed - you can use "dplyr::pull()" to make sure you get a vector.
Best
Daniel
-----Urspr?ngliche Nachricht-----
Von: G?bor Cs?rdi [mailto:csardi.gabor at gmail.com]
Gesendet: Dienstag, 26. September 2017 12:15
An: Daniel L?decke <d.luedecke at uke.de>
Cc: R Package Devel <r-package-devel at r-project.org>
Betreff: Re: [R-pkg-devel] tibbles are not data frames
What is the benefit here, compared to just calling as.data.frame() on it?
Gabor
On Tue, Sep 26, 2017 at 11:11 AM, Daniel L?decke <d.luedecke at uke.de> wrote:
> Since tibbles add their class attributes first, you could use:
>
> tb <- tibble(a = 5)
> inherits(tb, "data.frame", which = TRUE) == 1
>
> if "tb" is a data frame (only), TRUE is returned, for tibble FALSE.
> You could then coerce to data frame: as.data.frame(tb)
>
> -----Urspr?ngliche Nachricht-----
> Von: R-package-devel [mailto:r-package-devel-bounces at r-project.org] Im
> Auftrag von G?ran Brostr?m
> Gesendet: Dienstag, 26. September 2017 12:09
> An: r-package-devel at r-project.org
> Betreff: Re: [R-pkg-devel] tibbles are not data frames
>
>
>
> On 2017-09-26 11:56, G?bor Cs?rdi wrote:
>> On Tue, Sep 26, 2017 at 10:35 AM, Joris Meys <Joris.Meys at ugent.be> wrote:
>>> I don't like the dropping of dimensions either. That doesn't change
>>> the fact that a tibble reacts different from a data.frame. So
>>> tibbles do not inherit correctly from the class data.frame, and it
>>> can thus be argued that it's against OOP paradigms to pretend
>>> tibbles inherit from the class data.frame.
>>
>> I have yet to see an OOP system in which a subclass cannot override
>> the methods of its superclass. Not only is this in line with OOP
>> paradigms, it is actually one of the essential OOP features.
>>
>> To be more constructive, if you have a function that only works with
>> data frame inputs, then it is good practice to check that the
>> supplied input is indeed a data frame. This is independent of tibbles.
>
> It is not. I check input for being a data frame, but tibbles pass that test. That's the essence of the problem.
>
>> In practice it seems to me that an easy fix is to just call
>> as.data.frame on the input. This should either convert it to a data
>> frame, or throw an error.
>
> Sure, but I still need to rewrite the package.
>
> G?rn
>
>> For tibbles it
>> drops the tbl* classes.
>>
>> Gabor
>>
>>> Defensive coding techniques would check if it's a tibble and return
>>> an error saying a data.frame is expected. Unless tibbles inherit
>>> correctly from data.frame.
>>>
>>> I have nothing against tibbles. But calling them "data.frame" raises
>>> expectations that can't be fulfilled.
>>
>> [...]
>>
>> ______________________________________________
>> R-package-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>
> --
>
> _____________________________________________________________________
>
> Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen
> Rechts; Gerichtsstand: Hamburg | www.uke.de
> Vorstandsmitglieder: Prof. Dr. Burkhard G?ke (Vorsitzender), Prof. Dr.
> Dr. Uwe Koch-Gromus, Joachim Pr?l?, Martina Saurin (komm.)
> _____________________________________________________________________
>
> SAVE PAPER - THINK BEFORE PRINTING
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
--
_____________________________________________________________________
Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard G?ke (Vorsitzender), Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Pr?l?, Martina Saurin (komm.)
_____________________________________________________________________
SAVE PAPER - THINK BEFORE PRINTING