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

Possible off-label use of "column-nesting" tibbles #899

Closed
wasdoff opened this issue Jun 30, 2021 · 2 comments
Closed

Possible off-label use of "column-nesting" tibbles #899

wasdoff opened this issue Jun 30, 2021 · 2 comments

Comments

@wasdoff
Copy link

@wasdoff wasdoff commented Jun 30, 2021

Hey all,

I tried to find more info on the subject on the RStudio Community forum, but with little success. I'm re-posting over here in case someone may answer my question or if it's something that requires 'fixing' of some sort.

I noticed that if I have a tibble:

tibble_1 <- tibble(a = 1:10, b = 2:11, c = 3:12)

And I add this into another tibble using dplyr::mutate:

tibble_2 <- tibble(d = 4:13) %>%
    mutate(tibble_one = tibble_1)

The print output looks a bit funny:

# A tibble: 10 x 2
       d tibble_one$a    $b    $c
   <int>        <int> <int> <int>
 1     4            1     2     3
 2     5            2     3     4
 3     6            3     4     5
 4     7            4     5     6
 5     8            5     6     7
 6     9            6     7     8
 7    10            7     8     9
 8    11            8     9    10
 9    12            9    10    11
10    13           10    11    12

And, indeed, if I wanted to subset the colums I'd have to adress them as tibble_2$tibble_one$a, etc.
I accidentally came across this when I tried to get the result one would get with

tibble_2 <- tibble(d = 4:13) %>%
    mutate(tibble_one = pmap(tibble_1, c))

So my question is: what's the purpose behind this? Can it be used for something useful?

Thanks in advance.

By the way, I know it was silly to expect my desired outcome through the way that led me to this accidental discovery, but that's besides the point 😉.

@wasdoff
Copy link
Author

@wasdoff wasdoff commented Jun 30, 2021

An excellent reply by Davis Vaughan in the original forum thread has pointed out that these df-columns are entirely intentional and have some (limited) uses. Closing the issue.

@wasdoff wasdoff closed this as completed Jun 30, 2021
@github-actions
Copy link

@github-actions github-actions bot commented Jul 1, 2022

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 Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant