Skip to content
Prev 1920 / 12125 Next

[R-pkg-devel] tibbles are not data frames

Yes, basically tibbles violate the substitution principle. A lot of
other packages do, probably base R as well, although it is sometimes
hard to say, because there is no clear object hierarchy.

Let's take a step back, and see how you can check for a data frame argument.

1. Weak check.

is.data.frame(arg)

This essentially means that you trust subclasses of data.frame to
adhere to the substitution principle. While this is nice in theory, a
lot packages (including both major packages implementing subclasses of
data.frame!) do not always adhere. So this is not really a safe
solution.

Base R does this as well, sometimes, e.g. aggregate.data.frame has:

    if (!is.data.frame(x))
        x <- as.data.frame(x)

which is essentially equivalent to the weak check, since it leaves
data.frame subclasses untouched.

2. Strong "check".

arg <- as.data.frame(arg)

This is safer, because it does not rely on subclass implementors. It
also has the additional benefit that your code is polymorphic: it
works with any input, as long as it can be converted to a data frame.

Base R also uses this often, e.g. in merge.data.frame:

    nx <- nrow(x <- as.data.frame(x))
    ny <- nrow(y <- as.data.frame(y))

Gabor

Disclaimer: I do not represent the tibble authors in any way.

On Tue, Sep 26, 2017 at 11:21 AM, David Hugh-Jones
<davidhughjones at gmail.com> wrote:

Thread (48 messages)

Göran Broström tibbles are not data frames Sep 26 Stefan McKinnon Høj-Edwards tibbles are not data frames Sep 26 Alexandre Courtiol tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Stefan McKinnon Høj-Edwards tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Gábor Csárdi tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Daniel Lüdecke tibbles are not data frames Sep 26 Gábor Csárdi tibbles are not data frames Sep 26 David Hugh-Jones tibbles are not data frames Sep 26 Stefan McKinnon Høj-Edwards tibbles are not data frames Sep 26 Alexandre Courtiol tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Thierry Onkelinx tibbles are not data frames Sep 26 Holger Hoefling tibbles are not data frames Sep 26 CJ Yetman tibbles are not data frames Sep 26 Iñaki Ucar tibbles are not data frames Sep 26 Daniel Lüdecke tibbles are not data frames Sep 26 Pedro J. Aphalo tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Gábor Csárdi tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Jeroen Ooms tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Pedro J. Aphalo tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Göran Broström tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Joris Meys tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 Jens Oehlschlägel tibbles are not data frames Sep 26 Hadley Wickham tibbles are not data frames Sep 26 John C Nash tibbles are not data frames Sep 26 Dirk Eddelbuettel tibbles are not data frames Sep 26 Duncan Murdoch tibbles are not data frames Sep 26 John C Nash tibbles are not data frames Sep 26 Jim Lemon tibbles are not data frames Sep 26 Jens Oehlschlägel tibbles are not data frames Sep 27 Jens Oehlschlägel tibbles are not data frames Sep 27 Duncan Murdoch tibbles are not data frames Sep 27 Göran Broström Summary: tibbles are not data frames Sep 29