-
Notifications
You must be signed in to change notification settings - Fork 421
Closed
Labels
featurea feature request or enhancementa feature request or enhancementrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames
Description
Otherwise, duplicate column names may lead to hard-to-detect failures.
In the example below, an early mutate() that adds a column that exists in the sub-tibble breaks code that worked previously in a way that may go unnoticed. With universal names, the failure is detected immediately.
library(tidyverse)
data <- tibble(x = 1, b = list(tibble(a = 2:3)))
data
#> # A tibble: 1 x 2
#> x b
#> <dbl> <list>
#> 1 1 <tibble [2 × 1]>
old_data <-
data %>%
unnest()
old_data
#> # A tibble: 2 x 2
#> x a
#> <dbl> <int>
#> 1 1 2
#> 2 1 3
old_data %>% filter(a == 2)
#> # A tibble: 1 x 2
#> x a
#> <dbl> <int>
#> 1 1 2
new_data <-
data %>%
mutate(a = 1) %>% # This breaks existing code!
unnest()
new_data
#> # A tibble: 2 x 3
#> x a a1
#> <dbl> <dbl> <int>
#> 1 1 1 2
#> 2 1 1 3
new_data %>% filter(a == 2)
#> # A tibble: 0 x 3
#> # ... with 3 variables: x <dbl>, a <dbl>, a1 <int>
# Suggested fix: Safe failure
new_data <-
new_data %>%
rename(a..2 = a, a..3 = a1) %>%
filter(a == 2)
#> Error: Evaluation error: object 'a' not found.Created on 2018-10-25 by the reprex package (v0.2.1.9000)
Tested with c318c31.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancementrectangling 🗄️converting deeply nested lists into tidy data framesconverting deeply nested lists into tidy data frames