-
Notifications
You must be signed in to change notification settings - Fork 5
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
unexpected return from transmute() on nested data #20
Comments
That is correct,
|
Noted. I'm leaning towards the suppressMessages(library(tidyverse))
suppressMessages(library(data.table))
iris %>%
nest(-Species) %>%
unnest(data)
#> # A tibble: 150 x 5
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 setosa 5.1 3.5 1.4 0.2
#> 2 setosa 4.9 3 1.4 0.2
#> 3 setosa 4.7 3.2 1.3 0.2
#> 4 setosa 4.6 3.1 1.5 0.2
#> 5 setosa 5 3.6 1.4 0.2
#> 6 setosa 5.4 3.9 1.7 0.4
#> 7 setosa 4.6 3.4 1.4 0.3
#> 8 setosa 5 3.4 1.5 0.2
#> 9 setosa 4.4 2.9 1.4 0.2
#> 10 setosa 4.9 3.1 1.5 0.1
#> # ... with 140 more rows
irisDT <- iris %>%
nest(-Species) %>%
as.data.table()
irisDT[, unlist(data, recursive=FALSE), by = 'Species']
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1: setosa 5.1 3.5 1.4 0.2
#> 2: setosa 4.9 3.0 1.4 0.2
#> 3: setosa 4.7 3.2 1.3 0.2
#> 4: setosa 4.6 3.1 1.5 0.2
#> 5: setosa 5.0 3.6 1.4 0.2
#> ---
#> 146: virginica 6.7 3.0 5.2 2.3
#> 147: virginica 6.3 2.5 5.0 1.9
#> 148: virginica 6.5 3.0 5.2 2.0
#> 149: virginica 6.2 3.4 5.4 2.3
#> 150: virginica 5.9 3.0 5.1 1.8
irisDT[, unnest(.SD, data)]
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1: setosa 5.1 3.5 1.4 0.2
#> 2: setosa 4.9 3.0 1.4 0.2
#> 3: setosa 4.7 3.2 1.3 0.2
#> 4: setosa 4.6 3.1 1.5 0.2
#> 5: setosa 5.0 3.6 1.4 0.2
#> ---
#> 146: virginica 6.7 3.0 5.2 2.3
#> 147: virginica 6.3 2.5 5.0 1.9
#> 148: virginica 6.5 3.0 5.2 2.0
#> 149: virginica 6.2 3.4 5.4 2.3
#> 150: virginica 5.9 3.0 5.1 1.8
## loading table.express renders data.table code unusable
suppressMessages(library(table.express))
irisDT[, unnest(.SD, data)]
#> Error in .subset(x, j): invalid subscript type 'list'
irisDT %>%
select(unnest(.SD, data))
#> Error in .subset(x, j): invalid subscript type 'list'
irisDT %>%
group_by(Species) %>%
select(unlist(data, recursive=FALSE))
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1: setosa 5.1 3.5 1.4 0.2
#> 2: setosa 4.9 3.0 1.4 0.2
#> 3: setosa 4.7 3.2 1.3 0.2
#> 4: setosa 4.6 3.1 1.5 0.2
#> 5: setosa 5.0 3.6 1.4 0.2
#> ---
#> 146: virginica 6.7 3.0 5.2 2.3
#> 147: virginica 6.3 2.5 5.0 1.9
#> 148: virginica 6.5 3.0 5.2 2.0
#> 149: virginica 6.2 3.4 5.4 2.3
#> 150: virginica 5.9 3.0 5.1 1.8 |
Are you sure that is the example you meant to post? |
I extracted out the troublesome piece - The actual application is something like this - nested model in tibble. |
Ok. Yes, I think it's worth adding the parameter, it could also work for cases when you want to calculate something that should return a simple vector instead of a 1-column |
Thanks for the prompt update, as usual! |
Tested and worked as designed, but I'm still perplexed why this fails. suppressMessages(library(data.table))
suppressMessages(library(tidyverse))
irisDT <- as.data.table(iris) %>%
.[, nest(.SD), by = Species]
# works
irisDT[, unnest(.SD, data)]
#> Species Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1: setosa 5.1 3.5 1.4 0.2
#> 2: setosa 4.9 3.0 1.4 0.2
#> 3: setosa 4.7 3.2 1.3 0.2
#> 4: setosa 4.6 3.1 1.5 0.2
#> 5: setosa 5.0 3.6 1.4 0.2
#> ---
#> 146: virginica 6.7 3.0 5.2 2.3
#> 147: virginica 6.3 2.5 5.0 1.9
#> 148: virginica 6.5 3.0 5.2 2.0
#> 149: virginica 6.2 3.4 5.4 2.3
#> 150: virginica 5.9 3.0 5.1 1.8
## loading table.express renders data.table code unusable
suppressMessages(library(table.express))
irisDT %>%
start_expr() %>%
transmute(unnest(.SD, data), .enlist = FALSE)
#> .DT_[, unnest(.SD, data)]
# same expression as data.table but fails
irisDT %>%
transmute(unnest(.SD, data), .enlist = FALSE)
#> Error in .subset(x, j): invalid subscript type 'list' Created on 2019-08-02 by the reprex package (v0.2.1) |
That is annoying... Apparently, the If you execute That is very unfortunate because it means that any package that internally uses any I'll open a new issue and see if I can figure a workaround. |
Reprex below.
Issue:
select()
produced desired result, but nottransmute()
. The extralist(...)
generated in the expression fromtable.express
may be the issue.Created on 2019-07-28 by the reprex package (v0.2.1)
The text was updated successfully, but these errors were encountered: