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

Always left align column names for labelled vectors #678

Merged
merged 1 commit into from
Apr 26, 2022
Merged

Conversation

gorcha
Copy link
Member

@gorcha gorcha commented Apr 25, 2022

This PR left aligns column names for labelled vectors, closing #676.

For e.g.

library(tibble)
library(haven)

x <- tibble(
  col1 = labelled(
    c(1, 5, 8, 9, 1, 8),
    labels = c(Yes = 1, No = 5, `Don't know` = 8, Refused = 9)
  ),
  col2 = labelled(
    c(1, 12, 123, 1234, 1, 123),
    labels = c("a" = 1, "bcd" = 123)
  ),
  col3 = labelled(
    c(1, 12, 123, 1234, 12345, 123456789),
    labels = c("a" = 1, "bcd" = 123)
  ),
  col4 = labelled(
    c("a", "ab", "abc", "abcd", "abcde", "abcdefghijklmno"),
    labels = c("a" = "ab", "bcd" = "abcde")
  )
)

### Before
x
#> # A tibble: 6 × 4
#>             col1       col2            col3 col4           
#>        <dbl+lbl>  <dbl+lbl>       <dbl+lbl> <chr+lbl>      
#> 1 1 [Yes]           1 [a]           1 [a]   a              
#> 2 5 [No]           12              12       ab [a]         
#> 3 8 [Don't know]  123 [bcd]       123 [bcd] abc            
#> 4 9 [Refused]    1234            1234       abcd           
#> 5 1 [Yes]           1 [a]       12345       abcde [bcd]    
#> 6 8 [Don't know]  123 [bcd] 123456789       abcdefghijklmno

### After

x
#> # A tibble: 6 × 4
#>   col1           col2       col3            col4           
#>   <dbl+lbl>      <dbl+lbl>  <dbl+lbl>       <chr+lbl>      
#> 1 1 [Yes]           1 [a]           1 [a]   a              
#> 2 5 [No]           12              12       ab [a]         
#> 3 8 [Don't know]  123 [bcd]       123 [bcd] abc            
#> 4 9 [Refused]    1234            1234       abcd           
#> 5 1 [Yes]           1 [a]       12345       abcde [bcd]    
#> 6 8 [Don't know]  123 [bcd] 123456789       abcdefghijklmno

Created on 2022-04-25 by the reprex package (v2.0.1)

@gorcha gorcha requested a review from hadley April 25, 2022 03:08
@gorcha gorcha merged commit d913105 into main Apr 26, 2022
@gorcha gorcha deleted the pillar-alignment branch April 26, 2022 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants