Skip to content

R-devel change to cbind/rbind re FAQ 2.24 #3948

@mattdowle

Description

@mattdowle

Received from Kurt and posted here with permission.
Fantastic we can finally remove this workaround. Haven't looked in detail yet.

====

Matt,

You may have seen that in R-devel we've changed the {c,r}bind S3
dispatch mechanisms with

r77192 | hornik | 2019-09-15 20:45:30 +0200 (Sun, 15 Sep 2019) | 1 line
Switch default for c77141.

r77141 | hornik | 2019-09-04 07:47:13 +0200 (Wed, 04 Sep 2019) | 1 line
Allow experimenting with {c,r}bind() S3 dispatch.

(with a cleanup for the new default coming up once I get to it).

With these changes, for S3 dispatch {c,r}bind now use the first S3
method found, so that binding data frames and data tables now works "as
intended" in the sense that you get the method of the object binding to.

E.g.,

require("data.table")

cbind.data.frame <-
function (..., deparse.level = 1)
data.frame(..., check.names = FALSE)

cbind.data.table <-
function (..., deparse.level = 1)
{
if (!identical(class(..1), "data.frame"))
for (x in list(...)) {
if (inherits(x, "data.table"))
return(data.table::data.table(...))
}
data.frame(..., check.names = FALSE)
}

DF <- data.frame(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9)
DT <- data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9)

class(cbind(DF, DT))
class(cbind(DT, DF))

now gives

R> class(cbind(DF, DT))
[1] "data.frame"
R> class(cbind(DT, DF))
[1] "data.table" "data.frame"

Thus, for versions of R-devel later than r77192 you should now be able
to simply provide and register data.table methods for cbind and rbind
(instead of what you currently do in your startup code).

Can you please change data.table accordingly? Ideally, of course, as
quickly as possible ...

Best
-k

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions