-
Notifications
You must be signed in to change notification settings - Fork 130
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
as_tibble_row() #205
Comments
Maybe related? tidyverse/purrr#264 |
Connected to #219 presumably? |
named_vec <- c(uno = 1, dos = 2, tres = 3)
# uno dos tres
# 1 2 3
data.frame(as.list(named_vec))
# uno dos tres
# 1 1 2 3 One awkward place this shows up is when rowbinding lists of vectors. (vec_list <- list(named_vec, named_vec, named_vec))
## [[1]]
## uno dos tres
## 1 2 3
##
## [[2]]
## uno dos tres
## 1 2 3
##
## [[3]]
## uno dos tres
## 1 2 3
vec_list %>%
map(as.list) %>%
map_dfr(~.x)
## # A tibble: 3 x 3
## uno dos tres
## <dbl> <dbl> <dbl>
## 1 1 2 3
## 2 1 2 3
## 3 1 2 3 |
Wondering if this function could also solve the issue presented here, i.e., better control over handling mixed atomic and list columns when coercing to tibble:
|
@mkoohafkan: Sure, once we have this you should be able to use I'm not sure if this is still relevant, though, given that we are transitioning away from @garrettgman: I'm not sure how Vote to close this issue. |
I was never motivated by the I still think it's worth considering library(tibble)
as_tibble(list(a = 1:2, b = letters[3:5]))
#> Error: Column `a` must be length 1 or 3, not 2
as_tibble(c(a = 1:2, b = letters[3:5]))
#> # A tibble: 5 x 1
#> value
#> * <chr>
#> 1 1
#> 2 2
#> 3 c
#> 4 d
#> 5 e
tibble(list(a = 1:2, b = letters[3:5]))
#> # A tibble: 2 x 1
#> `list(a = 1:2, b = letters[3:5])`
#> <list>
#> 1 <int [2]>
#> 2 <chr [3]>
## this is what I actually want
tibble(a = list(1:2), b = list(letters[3:5]))
#> # A tibble: 1 x 2
#> a b
#> <list> <list>
#> 1 <int [2]> <chr [3]> Created on 2018-07-16 by the reprex package (v0.2.0.9000). I note that |
|
@krlmlr, it looks like the change resolves the row vs. column assumption when creating a tibble from a named vector as in the example by @garrettgman , but it doesn't address @jennybc or my examples for more intuitive handling of list columns. I still think there is a need for |
Postponing. |
Do we wrap scalars? as_tibble_row(a = 1) == tibble(a = list_of(1)) instead of as_tibble_row(a = 1) == tibble(a = 1) ? I think we should (for type stability), and perhaps invent a as_tibble_row(a = scalar(1)) == tibble(a = 1) and vec_c(scalar(1), scalar(2)) == vec_c(1, 2) . Alternatively, we could allow vec_c(1, list_of(2:3)) == list_of(1, 2:3) but not sure if this is consistent with the rest of vctrs. I'm experimenting with a CC @lionel-. |
|
First a note that it would be strange for an I agree that type-stability seems an issue. But a new scalar class is probably not the solution. Maybe this is just a convenience tool for exploring data? In this case type-stability wouldn't be as important, and it could auto-wrap anything that doesn't fit a row? It should be made clear that this isn't a good tool for programming. I guess users will end up using it for this purpose anyway. Or maybe have both |
Agreed that the function should be called Perhaps we could do: tibble_row(a = 1, b = 2:3, .scalars = list(c = 3)) ==
tibble(a = list(1), b = list(2:3), c = 3) |
Or: tibble_row(a = 1, b = 2:3, tibble(c = 3)) ==
tibble(a = list(1), b = list(2:3), c = 3) Or perhaps: tibble_wrap(a = 1, b = 2:3, tibble_scalar(c = 3)) ==
tibble(a = list(1), b = list(2:3), c = 3) |
From @jennybc foo <- list(a = 1:2, b = 1)
as_tibble_row(foo, .ptype = tibble(a = list(), b = int())) |
From @jennybc: To solve type stability, we always wrap in a column. Several possible ways to escape this:
|
I guess it's mostly |
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. |
Like as_tibble(), but expects atomics of length 1 or arbitrary objects and always wraps the latter with list(). Useful to undo the effects of dplyr::rowwise().
The text was updated successfully, but these errors were encountered: