Skip to content
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

Coercing a data.frame with a list column to a tibble #304

Closed
nbenn opened this issue Sep 6, 2017 · 2 comments
Closed

Coercing a data.frame with a list column to a tibble #304

nbenn opened this issue Sep 6, 2017 · 2 comments

Comments

@nbenn
Copy link

nbenn commented Sep 6, 2017

This might be a bit of an exotic bug report/feature request, but anyways, assume data.frame df as

df <- data.frame(a = 1:3, b = I(list(1, 1:2, 1:3)))
#   a       b
# 1 1       1
# 2 2    1, 2
# 3 3 1, 2, 3

now if this is coerced to a tibble as

as_tibble(df)
# # A tibble: 3 x 2
#       a          b
#   <int> <S3: AsIs>
# 1     1 <S3: AsIs>
# 2     2 <S3: AsIs>
# 3     3 <S3: AsIs>

the result is not what could be expected:

tibble::tibble(a = 1:3, b = list(1, 1:2, 1:3))
# # A tibble: 3 x 2
#       a         b
#   <int>    <list>
# 1     1 <dbl [1]>
# 2     2 <int [2]>
# 3     3 <int [3]>
@krlmlr
Copy link
Member

krlmlr commented Sep 12, 2017

The formatting looks odd, we'll definitely change it soon. But I don't think we should be stripping the AsIs class, because this seems merely a shortcut to be able to create a list column in the data.frame() constructor:

df <- data.frame(a = 1:3)
df$b <- list(1, 1:2, 1:3)
tibble::as_tibble(df)
#> # A tibble: 3 x 2
#>       a b        
#>   <int> <list>   
#> 1     1 <dbl [1]>
#> 2     2 <int [2]>
#> 3     3 <int [3]>

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants