-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dplyr_col_select()
reconstructs bare data.table objects
#6171
Conversation
``` Warning message: Topic 'glimpse': no parameters to inherit with @inheritParams ```
I am quite certain we don't want this to be data.table aware. The library(data.table)
# yay 32 rows, 0 cols
mtcars[0]
#> data frame with 0 columns and 32 rows
# 0 rows, 11 cols
as.data.table(mtcars)[0]
#> Empty data.table (0 rows and 11 cols): mpg,cyl,disp,hp,drat,wt... Try this with your two examples: library(data.table)
library(dplyr, warn.conflicts = FALSE)
d1 <- data.table(x = 1:2, y = 1:2)
attr(d1, "foo") <- "bar"
d2 <- dplyr:::dplyr_col_select(d1, "x")
d2 |
oh right. So maybe this is rather something to do in: if (identical(class(.data), "data.frame")) {
out <- dplyr_reconstruct(out, .data)
} |
Because this ends up calling if (!cedta()) {
# Fix for #500 (to do)
Nargs = nargs() - (!missing(drop))
ans = if (Nargs<3L) { `[.data.frame`(x,i) } # drop ignored anyway by DF[i]
else if (missing(drop)) `[.data.frame`(x,i,j)
else `[.data.frame`(x,i,j,drop)
# added is.data.table(ans) check to fix bug #81
if (!missing(i) && is.data.table(ans)) setkey(ans, NULL) # drops index too; tested by plyr::arrange test in other.Rraw
return(ans)
} |
Yea as you've seen I think the issue is basically that in non-data.table aware paths they just hand off to |
@@ -240,7 +240,7 @@ dplyr_col_select <- function(.data, loc, names = NULL, error_call = caller_env() | |||
|
|||
# Patch base data frames to restore extra attributes that `[.data.frame` drops. | |||
# We require `[` methods to keep extra attributes for all data frame subclasses. | |||
if (identical(class(.data), "data.frame")) { | |||
if (identical(class(.data), "data.frame") || identical(class(.data), c("data.table", "data.frame"))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to also mention the data.table handling in the comment and link to this PR
dplyr_col_select()
data table awaredplyr_col_select()
reconstructs bare data.table objects
mention this pr in comment |
Created on 2022-02-02 by the reprex package (v2.0.1)
as opposed to losing the attribute:
Created on 2022-02-02 by the reprex package (v2.0.1)
however, this only works with the dev version of
data.table
thanks to: Rdatatable/data.table#4909This is related to: fndemarqui/covid19br#1