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
grouped_df throws errors in add_column #303
Comments
Does |
Yes (with dev version of dplyr and tibble) |
Is the behavior any different with the CRAN version? |
No
Sent from a mobile device.
… On Sep 12, 2017, at 9:36 AM, Kirill Müller ***@***.***> wrote:
Is the behavior any different with the CRAN version?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Closing, we don't currently support |
The issue is about |
The problem is caused by the call of cbind here: Line 141 in 6320d77
|
Bummer. This seems to mean that we need to make |
Hmm, seems not ideal. |
@krlmlr I was just about to post an issue asking for For packages that extend Since So for my problem, either |
Most classes that build on top of |
SolutionI think I have something that fixes everyone's problems using https://github.com/DavisVaughan/tibble/blob/master/R/add.R#L141 Passes all tests for Fixes t-kalinowski's problemlibrary(dplyr, warn.conflicts = FALSE)
library(tibble)
df <- tibble(x = 1:3, y = 1:3)
df %>% add_column(z = 4:6, .before = "y")
#> # A tibble: 3 x 3
#> x z y
#> <int> <int> <int>
#> 1 1 4 1
#> 2 2 5 2
#> 3 3 6 3
df %>% group_by(x) %>% add_column(z = 4:6, .before = "y")
#> # A tibble: 3 x 3
#> # Groups: x [3]
#> x z y
#> <int> <int> <int>
#> 1 1 4 1
#> 2 2 5 2
#> 3 3 6 3 Fixes my own problemClasses and attrs are no longer lost. library(tibbletime)
#>
#> Attaching package: 'tibbletime'
#> The following object is masked from 'package:stats':
#>
#> filter
library(tibble)
data(FB)
FB <- as_tbl_time(FB, date)
class(FB)
#> [1] "tbl_time" "tbl_df" "tbl" "data.frame"
attr(FB, "index")
#> <quosure: frame>
#> ~date
FB <- FB %>% add_column(adj2 = FB$adjusted + 1)
class(FB)
#> [1] "tbl_time" "tbl_df" "tbl" "data.frame"
attr(FB, "index")
#> <quosure: frame>
#> ~date |
Thanks, happy to review a PR. |
- Prevent `add_column()` from dropping classes and attributes by removing the use of `cbind()`. Additionally this ensures that `add_column()` can be used with grouped data frames (#303, @DavisVaughan).
Closed by #306. |
- In `glimpse()`, compute `type_sum()` from data frame for dbplyr compatibility (#328). - `as_tibble.matrix()` repairs column names. - Compatible with R 3.1 (#323). - Make add_case() and alias for add_row() (#324, @LaDilettante). - `add_column()` to an empty zero-row tibble with a variable of nonzero length now produces a correct error message (#319). - Logical indexes are supported, a warning is raised if the length does not match the number of rows or 1 (#318). - Tibbles now support character subsetting (#312). - `as_tibble()` gains `rownames` argument (#288, #289). - Remove Rcpp dependency (#313, @patperry). - ``` `[.tbl_df`() ``` supports `drop = TRUE` and omits the warning if `j` is passed. The calls `df[i, j, drop = TRUE]` and `df[i, drop = TRUE]` are now compatible with data frames again (#307, #311). - Prevent `add_column()` from dropping classes and attributes by removing the use of `cbind()`. Additionally this ensures that `add_column()` can be used with grouped data frames (#303, @DavisVaughan). - Fixed width for word wrapping of the extra information (#301).
New formatting -------------- The new pillar package is now responsible for formatting tibbles. Pillar will try to display as many columns as possible, if necessary truncating or shortening the output. Colored output highlights important information and guides the eye. The vignette in the tibble package describes how to adapt custom data types for optimal display in a tibble. New features ------------ - Make `add_case()` an alias for `add_row()` (#324, @LaDilettante). - `as_tibble()` gains `rownames` argument (#288, #289). - `as_tibble.matrix()` repairs column names. - Tibbles now support character subsetting (#312). - ``` `[.tbl_df`() ``` supports `drop = TRUE` and omits the warning if `j` is passed. The calls `df[i, j, drop = TRUE]` and `df[i, drop = TRUE]` are now compatible with data frames again (#307, #311). Bug fixes --------- - Improved compatibility with remote data sources for `glimpse()` (#328). - Logical indexes are supported, a warning is raised if the length does not match the number of rows or 1 (#318). - Fixed width for word wrapping of the extra information (#301). - Prevent `add_column()` from dropping classes and attributes by removing the use of `cbind()`. Additionally this ensures that `add_column()` can be used with grouped data frames (#303, @DavisVaughan). - `add_column()` to an empty zero-row tibble with a variable of nonzero length now produces a correct error message (#319). Internal changes ---------------- - Reexporting `has_name()` from rlang, instead of forwarding, to avoid warning when importing both rlang and tibble. - Compatible with R 3.1 (#323). - Remove Rcpp dependency (#313, @patperry).
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
digging into this a little it seems to be caused by
cbind()
returning a matrix when called on a grouped_dfThe text was updated successfully, but these errors were encountered: