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
relocate #232
Comments
Thanks for reporting. From what I understand, piping Your code:
is just a complicated way of writing When piping a lazy dt (ie an object of class library(data.table)
library(dplyr,warn.conflicts = FALSE)
library(dtplyr)
flights_lazyDT <- dtplyr::lazy_dt(nycflights13::flights)
flights_DT <- flights_lazyDT %>% as.data.table()
out <- flights_lazyDT %>%
relocate(where(is.character), .before = where(is.numeric))
class(flights_DT)
#> [1] "data.table" "data.frame"
class(out)
#> [1] "dtplyr_step_first" "dtplyr_step" Created on 2021-03-27 by the reprex package (v1.0.0) With that said, it does seem like you're found an issue with library(data.table)
library(dplyr,warn.conflicts = FALSE)
flights_DT <- as.data.table(nycflights13::flights)
out2 <- flights_DT %>%
relocate(where(is.character), .before = where(is.numeric))
out3 <- flights_DT %>%
group_by(month) %>%
summarize(x=mean(dep_delay,na.rm=TRUE))
class(out2)
#> [1] "data.table" "data.frame"
class(out3)
#> [1] "tbl_df" "tbl" "data.frame" Created on 2021-03-27 by the reprex package (v1.0.0) |
@myoung3 As of dtplyr v1.1.0 one of the new features is that the library(dtplyr)
library(data.table)
library(dplyr)
test_dt <- data.table(x = 1:3, y = 1:3)
test_dt %>%
mutate(double_x = x * 2)
#> Source: local data table [3 x 3]
#> Call: copy(`_DT1`)[, `:=`(double_x = x * 2)]
#>
#> x y double_x
#> <int> <int> <dbl>
#> 1 1 1 2
#> 2 2 2 4
#> 3 3 3 6
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results It looks like |
@markfairbanks Very cool! I had missed that. Sorry, @D-Se. My mistake. And on the second point I was mistaken as well, it seems dplyr's behavior (whether it returns a tibble or a data.frame) actually depends on the function. https://stackoverflow.com/questions/61067989/which-tidyverse-functions-return-tibbles |
Relocate executes and yields data table directly, without a as.data.table call
The text was updated successfully, but these errors were encountered: